iOS8 Push Notifications
本文转载至 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的更多相关文章
- [Erlang 0106] Erlang实现Apple Push Notifications消息推送
我们的IOS移动应用要实现消息推送,告诉用户有多少条消息未读,类似下图的效果(笑果),特把APNS和Erlang相关解决方案笔记于此备忘. 上面图片中是Apple Notif ...
- 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 ...
- iOS 中的Push Notifications简单实现(APNS)
Android中的通知只有一种,就是Local Notifications,而iOS中除了Local Notifications外,还有一种Push Notifications.ios的这2种noti ...
- Apple Remote Push Notifications
1.帮助文档参考: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/Remote ...
- (转)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 ...
- Xcode - Your development team, "", does not support the Push Notifications capability.
1.问题描述: 从git上checkout了别人的一个工程文件,选择team时,Xcode显示如下问题 Your development team, "xxx.xxx.xxx", ...
- [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 ...
- Your development team, "", does not support the Push Notifications capability.
问题: Your development team, "", does not support the Push Notifications capability. 解决方法: 1 ...
- iOS10 App适配权限 Push Notifications 字体Frame 遇到的坑!!!!
添加配置权限 <!-- 相册 --> <key>NSPhotoLibraryUsageDescription</key> <string>"x ...
随机推荐
- C语言实现DES算法
原文转自 http://www.cnblogs.com/imapla/archive/2012/09/07/2674788.html 用C语言实现DES(数据加密算法)的一个例子,密文和密钥都是8个字 ...
- linux .so .a .o 文件
linux下文件的类型是不依赖于其后缀名的,但一般来讲:.o,是目标文件,相当于windows中的.obj文件.so 为共享库,是shared object,用于动态连接的,和dll差不多.a为静态库 ...
- Codeforces Gym101502 F.Building Numbers-前缀和
F. Building Numbers time limit per test 3.0 s memory limit per test 256 MB input standard input ou ...
- bzoj 1552: [Cerc2007]robotic sort
1552: [Cerc2007]robotic sort Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1198 Solved: 457[Submit] ...
- SSL/TLS协议
今天闲着给自己的网站申请了一个免费证书,顺便复习下SSL/TLS协议 (https 就是在http+ssl协议) SSL介绍: 安全套接字(Secure Socket Layer,SSL)协议是 ...
- JDK1.8中的Lambda表达式和Stream
1.lambda表达式 Java8最值得学习的特性就是Lambda表达式和Stream API,如果有python或者javascript的语言基础,对理解Lambda表达式有很大帮助,因为Java正 ...
- kafka生产者客户端
kafka的生产者 1. 生产者客户端开发 熟悉kafka的朋友都应该知道kafka客户端有新旧版本,老版本采用scala编写,新版本采用java编写.随着kafka版本的升级,旧版本客户端已经快 ...
- iOS开发 准确计算Coretext高度
- (int)getAttributedStringHeightWithString:(NSAttributedString *) string WidthValue:(int) width{ ...
- 记一次CDH修改IP
因机房服务器搬迁,需要修改CDH ip ,集群中有6台服务器. 其中配置了ldap,其中卡在了ldap中的坑太深,所以记录一下. 一.服务器IP等地址修改 1.首先在安装cloudera-manage ...
- 大牛blog汇总
系列专题的文件夹 01. Java String系列 (共3篇) 02. Java异常系列 (共3篇) 03. Java 时间日期系列 (共7篇) 04. java io系列 (共26篇) 05, J ...