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


阅读更多
上一篇iOS 真机调试
下一篇Android 视频播放器 应用层设计 考虑事项(一)
想对作者说点什么? 我来说一句

C# apns 推送消息

2014年01月24日 16KB 下载

没有更多推荐了,返回首页

关闭
关闭