2010-04-01 107 views
7

我需要在我的應用程序中實現推送通知。 其實我必須從服務器接收消息。 請引導我如何在我的iPhone應用程序中實現推送通知。Iphone應用程序中的推送通知

+3

不要忘了接受的答案,幫助你 – 2011-05-24 05:46:06

回答

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); 

} 
+0

有沒有別的東西我想do.just問,因爲我已經在iPhone應用ABT豪華通知沒有詳細的想法 – 2010-04-01 11:40:33

+0

在客戶端沒有什麼... – 2010-04-01 12:20:36

+2

一件事您需要使用推送通知啓用提供配置文件來構建您的應用 – 2011-01-25 05:32:28

7

客戶端的東西很容易實現這兩個委託方法,但如果你想有一個很好的例子,我們提供一個可以下載的http://bitbucket.org/urbanairship/push_sample/

你」我發現服務器端的東西要困難得多,因此我會推薦使用Urban Airship,因爲我們提供了一個簡單的RESTful服務,您可以使用大量的附加功能,而獨立軟件包是免費的。

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

警告:我在那裏工作。

+0

注意:城市飛艇不是免費的 – Marty 2012-06-04 10:13:21

+1

對於大多數應用來說,每月發送少於1M條消息是免費的。 – lolsborn 2012-07-10 20:35:48