博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

   Push远程通知的前提是,调试或者发布时,证书已经启动了Push服务。

       1. 注册远程通知类型

       - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
       {
              // 注册通知
              UIRemoteNotificationType apn_type = (UIRemoteNotificationType)(UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeBadge);
           [[UIApplication sharedApplication] registerForRemoteNotificationTypes:apn_type]; 

             // 其它代码
             // ...
       }

       2. 实现appDelegate的委托方法

       - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
       {
           NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
           NSString *deviceToken = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
    
           NSLog(@"deviceToken:%@", deviceToken);
    
           //这里可以把deviceToken发给自己的服务器
       }

       3. 获取失败回调

       - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
       {
           NSLog(@"didFailToRegisterForRemoteNotificationsWithError:%@", [error localizedDescription]);
       }

       4. 接收到远程通知

       - (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
       {
          NSLog(@"receive remote notification:%@", userInfo);
       }

 

 下面这篇文章也挺好的

http://blog.csdn.net/ios_che/article/details/7428413

posted on 2013-06-02 13:36  Likwo  阅读(4610)  评论(0编辑  收藏  举报