APNs Apple Push Notification Services 推送消息

来源:互联网 发布:重庆编程学校 编辑:程序博客网 时间:2024/05/16 06:10

是否使用APNs?

首先,APNs不是绝对可靠;它可以取代SMS,  但是在某些情况下也可能代价高昂。

I would like to receive Push Notifications on my iPhone (instead of using expensive SMS gateway services).



一、配置流程

  1. CSR ,保存私钥,设置密码
  2. 在新建app IDs的时候就生成SSL certificate(貌似与一般的证书生成不同)
  3. 制作pem文件,方便Your Server使用。 以下三合一

  • The CSR
  • The private key as a p12 file (PushChatKey.p12)
  • The SSL certificate, aps_developer_identity.cer

二、APNs交互流程



三、代码节选


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{self.window.rootViewController = self.viewController;[self.window makeKeyAndVisible]; // Let the device know we want to receive push notifications[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];     return YES;}

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken{NSLog(@"My token is: %@", deviceToken);} - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error{NSLog(@"Failed to get token, error: %@", error);}


如果收不到apn消息:

1.请检查网络是否正常; 

2.应用程序目前是否在前台,如在前台请切换至后台。


参考:

http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12

http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html

http://blog.mobileroadie.com/2011/06/best-practices-on-push-notifications/

http://mobiforge.com/developing/story/programming-apple-push-notification-services


原创粉丝点击