本文转载至 http://blog.csdn.net/pjk1129/article/details/39551887

 

原贴地址:https://parse.com/tutorials/ios-push-notifications

github地址:https://github.com/ParsePlatform/PushTutorial

iOS Push通知已经广泛应用于实际开发中,iOS8与之前注册push有所不同,这里把如何潜入代码贴一下,以作记录,详情请看上面地址链接

Adding Code for a Push Enabled iOS Application

We are now ready to start programming. We need to make a few modification to the app delegate in order to receive push notifications.

To register the current device for push, call the method[application registerForRemoteNotifications] in the app delegate's-application:didFinishLaunchingWithOptions: method.

- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

...

// Register for Push Notitications, if running iOS 8

if ([applicationrespondsToSelector:@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)];

}

...

}

If the registration is successful, the callback method-application:didRegisterForRemoteNotificationsWithDeviceToken: in the application delegate will be executed. We will need to implement this method and use it to inform Parse about this new device.

- (void)application:(UIApplication *)applicationdidRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {

// Store the deviceToken in the current installation and save it to Parse.

PFInstallation *currentInstallation = [PFInstallationcurrentInstallation];

[currentInstallation setDeviceTokenFromData:deviceToken];

currentInstallation.channels = @[@"global" ];

[currentInstallation saveInBackground];

}

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 *)applicationdidReceiveRemoteNotification:(NSDictionary *)userInfo {

[PFPush handlePush:userInfo];

}

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.

iOS8 Push Notifications的更多相关文章

  1. [Erlang 0106] Erlang实现Apple Push Notifications消息推送

        我们的IOS移动应用要实现消息推送,告诉用户有多少条消息未读,类似下图的效果(笑果),特把APNS和Erlang相关解决方案笔记于此备忘.          上面图片中是Apple Notif ...

  2. Send Push Notifications to iOS Devices using Xcode 8 and Swift 3, APNs Auth Key

    Send Push Notifications to iOS Devices using Xcode 8 and Swift 3 OCT 6, 2016 Push notifications are ...

  3. iOS 中的Push Notifications简单实现(APNS)

    Android中的通知只有一种,就是Local Notifications,而iOS中除了Local Notifications外,还有一种Push Notifications.ios的这2种noti ...

  4. Apple Remote Push Notifications

    1.帮助文档参考: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/Remote ...

  5. (转)pem, cer, p12 and the pains of iOS Push Notifications encryption

    转自:http://cloudfields.net/blog/ios-push-notifications-encryption/ The serious pains of setting up a ...

  6. Xcode - Your development team, "", does not support the Push Notifications capability.

    1.问题描述: 从git上checkout了别人的一个工程文件,选择team时,Xcode显示如下问题 Your development team, "xxx.xxx.xxx", ...

  7. [PWA] Add Push Notifications to a PWA with React in Chrome and on Android

    On Android and in Chrome (but not on iOS), it's possible to send push notifications with a PWA. We'l ...

  8. Your development team, "", does not support the Push Notifications capability.

    问题: Your development team, "", does not support the Push Notifications capability. 解决方法: 1 ...

  9. iOS10 App适配权限 Push Notifications 字体Frame 遇到的坑!!!!

    添加配置权限 <!-- 相册 --> <key>NSPhotoLibraryUsageDescription</key> <string>"x ...

随机推荐

  1. 2018.8.6 Noip2018模拟测试赛(十九)

    日期: 八月六号  总分: 300分  难度: 提高 ~ 省选    得分: 10分(MMP) 题目目录: T1:Tree T2:异或运算 T3:Tree Restoring 赛后反思: Emmmmm ...

  2. 转 markdown编写规则、语法

    http://www.jianshu.com/p/1e402922ee32/ Markdown——入门指南 字数2231 阅读307754 评论115 喜欢1350 转载请注明原作者,如果你觉得这篇文 ...

  3. 标准C程序设计七---52

    Linux应用             编程深入            语言编程 标准C程序设计七---经典C11程序设计    以下内容为阅读:    <标准C程序设计>(第7版) 作者 ...

  4. 标准C程序设计七---35

    Linux应用             编程深入            语言编程 标准C程序设计七---经典C11程序设计    以下内容为阅读:    <标准C程序设计>(第7版) 作者 ...

  5. rp6818 和rp4418 重点修改的kernel几个问题!

    kernel\arch\arm\plat-s5p6818\drone\include文件下#define PAD_GPIOD1     (PAD_MODE_ALT | PAD_FUNC_ALT1 | ...

  6. spring版本不兼容JDK问题

    在实验书上Spring项目的时候出现一个问题,导入包和使用注释的时候eclipse出现报错. 导入包报错:The import org cannot be resolved 注释报错:componen ...

  7. vs code theme Seti monokai

    http://www.jianshu.com/p/80e983201f86 Seti-UI主题是一款极具传奇色彩的主题

  8. java性能监控工具jstat-windows

    jstat Monitors Java Virtual Machine (JVM) statistics. This command is experimental and unsupported. ...

  9. Linux 学习之虚拟机下的网络连接

    参考资料: http://wenku.baidu.com/link?url=_55RWvvBKQDoZjQSo-HQ3TdmLIzX1zkA_g1znCw0IXkwvxbxMiA3KfpyaL-lhv ...

  10. C#应该掌握的一些东西

    C#应该掌握的一些东西   随着培训机构的增多,越来越多的人进入IT行业.那么对于我们这些自学出来,经验不够丰富的转行者来说,我们需要掌握最起码的一些东西,这对于面试很有用,而且在工作中也很常用.本人 ...