本文转载至 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. zoj 1425 最大交叉匹配

    Crossed Matchings Time Limit: 2 Seconds      Memory Limit: 65536 KB There are two rows of positive i ...

  2. 【CF707B】Bakery(想法题)

    题意: 有N个城市,M条无向边,其中有K个城市是仓库 现在要在非仓库的城市中选择一家开面包店,使得其最少与一个仓库联通,且到所有仓库距离的最小值最小 (1 ≤ n, m ≤ 10^5, 0 ≤ k ≤ ...

  3. [LeetCode] Edit Distance 字符串变换为另一字符串动态规划

    Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2 ...

  4. 彻底搞定C指针-函数名与函数指针【转】

    转自:http://blog.csdn.net/a1232345/article/details/43524371 函数名与函数指针 一 通常的函数调用    一个通常的函数调用的例子://自行包含头 ...

  5. 诡异的malloc函数和%S的输出

    今天测试代码过程中无意间发现,代码如下: #include <stdio.h> #include <string.h> #include <stdlib.h> #d ...

  6. Android系统默认输入法的修改为搜狗输入法

    1.  frameworks\base\packages\SettingsProvider\res\values\defaults.xml 文件中修改默认输入法为搜狗输入法 <stringnam ...

  7. 关于unity3d插件的自动打包

    开发中,迩可能会遇到在xcode里添加一些需要调用原生api的方法,可能是game center,可能是内购之类的,但是这些插件实在太多了,所以迩大可不必自己写这些插件,问题在于,国内的一些插件,像9 ...

  8. chroot下二进制程序迁移

    #!/bin/bash # #define function#Copy binary programcp_bin(){ cmd_dir=${cmd_path%/*} [ ! -d /mnt/sysro ...

  9. LeetCode OJ--Set Matrix Zeroes **

    http://oj.leetcode.com/problems/set-matrix-zeroes/ 因为空间要求原地,所以一些信息就得原地存储.使用第一行第一列来存本行本列中是否有0.另外对于第一个 ...

  10. python学习之-- 生成唯一ID

    以下以2种方法生成唯一ID def uuid_method(): """第一种方法""" import uuid return str(uu ...