关闭

APNs Apple Push Notification Services 推送消息

920人阅读 评论(0) 收藏 举报

是否使用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


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:576864次
    • 积分:7437
    • 等级:
    • 排名:第3029名
    • 原创:168篇
    • 转载:43篇
    • 译文:0篇
    • 评论:128条
    最新评论