APNs Apple Push Notification Services 推送消息

是否使用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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值