本文转载至 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. vue 配合 element-ui使用搭建环境时候遇到的坑

    在需要使用element-ui的时候,直接引入文件,发现会报错,解析不了css文件和字体,需要在webpack里面配置上css-loader和style-loader,最好的做法是把element-u ...

  2. poj 1637 混合图欧拉回路 学习笔记

    题目大意 求混合图是否存在欧拉回路 做法 有向边我们只有增加入度出度 对于无向边,我们给它设定一个初始方向 如果不能满足|入度-出度|为偶数,无解 然后在网络流图中, 设设定方向的反向连一条边,表示反 ...

  3. TYVJ 1305 最大子序和 ++ 烽火传递

    描述 输入一个长度为n的整数序列,从中找出一段不超过M的连续子序列,使得整个序列的和最大. 例如 1,-3,5,1,-2,3 当m=4时,S=5+1-2+3=7当m=2或m=3时,S=5+1=6 输入 ...

  4. linux 下 异步IO

    方法一:使用fcntl来置O_ASYNC位. 这个方法的效果是,当输入缓存中的输入数据就绪时(输入数据可读),内核向用F_SETOWN来绑定的那个进程发送SIGIO信号.此时程序应该用getchar等 ...

  5. libstdc++.so.6: version `GLIBCXX_3.4.20' not found

    libstdc++.so.6: version `GLIBCXX_3.4.20' not found 参考链接: (1)解决/usr/lib/libstdc++.so.6: version `GLIB ...

  6. BZOJ——2134: 单选错位

    http://www.lydsy.com/JudgeOnline/problem.php?id=2134 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: ...

  7. 洛谷—— P3865 【模板】ST表

    https://www.luogu.org/problemnew/show/P3865 题目背景 这是一道ST表经典题——静态区间最大值 请注意最大数据时限只有0.8s,数据强度不低,请务必保证你的每 ...

  8. SpringBoot中如何上传Upload

    [学习笔记] 5.上传:马克-to-win@马克java社区:根据第3部分的helloworld例子,用那个项目做底子.pom.xml都不用改变.参考项目bootUpload1.static/inde ...

  9. JSP页面顶端出现错误:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path的问题解决

    原理:把RunTime容器添加进去,比如tomcat的. 1.项目右键->[Build Path]->[Configure Build Path...] 2.把tomcat的runtime ...

  10. 【spring boot】5.spring boot 创建web项目并使用jsp作前台页面

    贼烦的是,使用spring boot 创建web项目,然后我再idea下创建的,but 仅仅启动spring boot的启动类,就算整个项目都是好着的,就算是能够进入controller中,也不能成功 ...