在Iphone应用程序中推送通知

时间:2010-04-01 06:59:08

标签: iphone objective-c push-notification

我需要在我的应用程序中实现推送通知。 实际上我必须从服务器接收消息。 请指导我如何在我的iphone应用程序中实现推送通知。

2 个答案:

答案 0 :(得分:7)

客户端的东西很简单,但如果你想要一个很好的例子,我们提供一个你可以下载的http://bitbucket.org/urbanairship/push_sample/

你会发现服务器方面的东西要困难得多,为此我建议使用Urban Airship,因为我们提供了一个简单的REST服务,你可以使用很多附加功能,独立包是免费的。

http://urbanairship.com/docs/push_index.html

警告:我在那里工作。

答案 1 :(得分:3)

您需要在应用程序中实现这两个委托方法

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
    //NSLog(@"Entered into Method");
    NSString *myDevTokenString = [devToken description];
    NSLog(myDevTokenString);
    self.tokenAsString = [[devToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
    NSLog(@"token As String:%@", tokenAsString);
    //const void *devTokenBytes = [devToken bytes];
    //NSLog(@"My Token is : %@",devToken);
    //self.registered = YES;
//  UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"APNClient-GotToken" message:myDevTokenString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
//  [myAlert show];
//  [myAlert release];
    //[self sendProviderDeviceToken:devTokenBytes]; // custom method

}

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {

    //UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"APNClient" message:@"called -Error- Method" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
//  [myAlert show];
//  [myAlert release];
    NSString *errText = [[NSString alloc] initWithFormat:@"APN Error:%@",err];
    NSLog(@"Error in registration. Error: %@", errText);

}
相关问题