是否使用APNs?
首先,APNs不是绝对可靠;它可以取代SMS, 但是在某些情况下也可能代价高昂。
I would like to receive Push Notifications on my iPhone (instead of using expensive SMS gateway services).
一、配置流程
二、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