标签:push
给iOS程序添加push代码 Adding Code for a Push Enabled iOS Application/*代码*/ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... // Register for Push Notitications, if running iOS 8 if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound); UIUserNotificationSettings *settings = [UIUserNotificationSettingssettingsForTypes:userNotificationTypes categories:nil]; [application registerUserNotificationSettings:settings]; [application registerForRemoteNotifications]; } else { // Register for Push Notifications before iOS 8 [application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)]; } ... }
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { // Store the deviceToken in the current installation and save it to Parse. PFInstallation *currentInstallation = [PFInstallation currentInstallation]; [currentInstallation setDeviceTokenFromData:deviceToken]; currentInstallation.channels = @[@"global" ]; [currentInstallation saveInBackground]; }
这种情况,我们简单调用解析,解析器创建一个模态alert并显示push的内容。
另外:如果程序完全退出,先调用didFinishLaunchingWithOptions把程序启动起来。
When a push notification is received while the application is not
in the foreground, it is displayed in the iOS Notification Center. However, if the notification is received while the app is active, it is up to the app to handle it. To do so, we can implement the [application:didReceiveRemoteNotification] method
in the app delegate. In our case, we will simply ask Parse to handle it for us. Parse will create a modal alert and display the push notification‘s content.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [PFPush handlePush:userInfo]; }
是否允许发送push通知。
You should now run your application (on your iOS device) to make sure everything is set up correctly. If it is, the first time you run this app you should see a
modal alert requesting permission from the user to send push notifications.
原贴地址:https://parse.com/tutorials/ios-push-notifications
github地址:https://github.com/ParsePlatform/PushTutorial
标签:push
原文地址:http://blog.csdn.net/hherima/article/details/44854373