本文转载至 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. hdu 1250 树形DP

    Anniversary party Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  2. C#:使用WebRequest类请求数据

    本文翻译于:https://msdn.microsoft.com/en-us/library/456dfw4f(v=vs.110).aspx 下列程序描述的步骤用于从服务器请求一个资源,例如,一个We ...

  3. vue2 父子组件间通信

    父组件往子组件传值 props 传text father.vue <template> <div class="father"> {{'我是父组件'}} & ...

  4. JSTL <C:if></C:if> 和<C:ForEach></C:ForEach> 入门级~

    一.<C:If>标签:条件判断语句 <c:if test="${objList.nodetype == 1}">上级节点</c:if>   te ...

  5. AT&T汇编语言及其寻址方式

    汇编语言论风格来分主要是两类,一类是Intel汇编,一类是AT&T汇编,分别被Windows和Linux作为主流风格.因为我博客以推荐Linux系统为主,所以以后多以Linux汇编为主要描述语 ...

  6. 23深入理解C指针之---数组的基础

    数组是c语言内置的数据结构,数组有一维数组.二维数组和多维数组.使用数组传递数组时,必须传入数组的大小. 一.数组的特征:阐明数组的特点 1.数组要素: 1).数组类型:数组中存储的数据的类型: 2) ...

  7. Install Qualcomm Development Environment

    安裝 Android Development Environment http://www.cnblogs.com/youchihwang/p/6645880.html 除了上述還得安裝, sudo ...

  8. JProfile 9.2 linux安装及windows客户端远程监控

    http://blog.csdn.net/fengzhou0920/article/details/52119039 1.       测试环境 服务器:Linux X64;tomcat 7.0;jd ...

  9. 机器学习实战读书笔记(五)Logistic回归

    Logistic回归的一般过程 1.收集数据:采用任意方法收集 2.准备数据:由于需要进行距离计算,因此要求数据类型为数值型.另外,结构化数据格式则最佳 3.分析数据:采用任意方法对数据进行分析 4. ...

  10. nfs详解及实现全网备份

    1.统一hosts cat /etc/hosts 172.16.1.5 lb01 172.16.1.6 lb02 172.16.1.7 web02 172.16.1.8 web01 172.16.1. ...