iOS 8 Apple Push Notification Service

  • Apple Configuration
    • 1. create Apple ID in Apple Developer Website
    • 2. check on "Push Notification" in the functionality
    • 3. configure for Push Notification in Development: create certificate
      • 3.1 upload the certificate file which is generated by keychain access.

        • how to generating the Certificate Signing Request (CSR):
        • 3.1.1 keychain access -> certificate assistant -> request a certificate from a certificate authority
        • 3.1.2 save the certificate file to the disk as "your name.certSigningRequest", which will be used to be uploaded.
      • 3.2 download SSL Certificate and save as “aps_development.cer”
      • 3.3 click the “aps_development.cer” to install, you will see it in keychain access, export as .p12 file
      • 3.4 use command line to transform it from .p12 to .pem, which will be used in the server. keep in mind for the password, which will also be used in the server
        • $ openssl pkcs12 -in cert.p12 -out apple_push_notification.pem -nodes -clcerts
    • 4. create provision file for this Apple ID: generate and drag it to Xcode

  • Xcode Side

In AppDelegate.m, implement the methods below:

//---------------------------------------------
#pragma mark - App Delegate
//---------------------------------------------
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    //---------------------------------------------
    // set push notification
    //---------------------------------------------
    if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
    {
        // iOS 8 Notifications
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

        [application registerForRemoteNotifications];
    }
    else
    {
        // iOS < 8 Notifications
        [application registerForRemoteNotificationTypes:
         (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
    }

    //---------------------------------------------
    //Accept push notification when app is not open
    //---------------------------------------------
    NSDictionary *remoteNotification = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
    if (remoteNotification) {
        //        [self handleRemoteNotification:application userInfo:remoteNotif];
    }
    else{
        // do nothing ..
    }

    return YES;
}
//---------------------------------------------
#pragma mark - Push Notifications Delegate
//---------------------------------------------
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
    NSLog(@"This device token is: %@", deviceToken);
    NSString *token = [[[[deviceToken description]
                         stringByReplacingOccurrencesOfString: @"<" withString: @""]
                        stringByReplacingOccurrencesOfString: @">" withString: @""]
                       stringByReplacingOccurrencesOfString: @" " withString: @""];

    // call the server function to register this device
    // ..
}

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
    NSLog(@"Failed to get token, error: %@", error);
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
    NSLog(@"didReceiveRemoteNotification");

    UIApplicationState applicationState = application.applicationState;
    if ( applicationState == UIApplicationStateActive ){
        // app was already in the foreground
        NSLog(@"Content: %@", [[userInfo objectForKey: @"aps"] objectForKey: @"alert"]);

        UIRemoteNotificationType enabledTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
        if (enabledTypes & UIRemoteNotificationTypeBadge) {
            //badge number is enabled
        }
        if (enabledTypes & UIRemoteNotificationTypeSound) {
            //sound is enabled
        }
        if (enabledTypes & UIRemoteNotificationTypeAlert) {
            //alert msg is enabled
        }
    }
    else{
        // app was just brought from background to foreground
    }
}

  • Server Side(Ruby on Rails):

Gem Recomend: https://github.com/nomad/Houston

  • Reference:
[1]http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1

[2]https://www.youtube.com/watch?v=_3YlqWWnI6s

时间: 2024-08-24 11:47:51

iOS 8 Apple Push Notification Service的相关文章

Unity3d 在 iOS 上推送( push notification ) 编写

div#cpmenu {height:200px;float:left;} div#cpcontent {height:200px;width:150px;float:left;} 文章作者:松阳 原文链接:http://blog.csdn.net/fansongy/article/details/43954515 配置证书 先按照这个生成一大堆证书 http://www.cnblogs.com/gpwzw/archive/2012/03/31/apple_push_notification_s

iOS上简单推送通知(Push Notification)的实现

http://blog.csdn.net/daydreamingboy/article/details/7977098 iOS上简单推送通知(Push Notification)的实现 根据这篇很好的教程(http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12),结合自己的实践,写下一点笔记,仅供参考:) 由于篇幅较长,我列出简单的目录,如下 1) 理解Apple推送通知的机制 2)

&quot;Missing Push Notification Entitlement&quot;警告-----以及解决方法

最近开发的cordova应用,要做ios的适配,并且发布版本,但是有一次在发测试版本的时候,突然收到一封邮件警告,原文如下: Missing Push Notification Entitlement - Your app appears to include API used to register with the Apple Push Notification service, but the app signature’s entitlements do not include the

iOS开发中通知(Notification)快速入门及推送通知实现教程

iOS开发中通知(Notification)快速入门及推送通知实现教程 标签: NSNotificationCenterNSNotification 2016-11-14 00:18 232人阅读 评论(0) 收藏 举报  分类: iOS(400)  转载自:http://www.111cn.NET/sj/ios8/90190.htm 通知(Notification)是开发框架中观察者模式的一种实现方式,内部的实现机制由Cocoa框架支持,通常用于试图控制器和数据模型的交互.通过通知,可以向一个

Push Notification Doc

Baidu Push Notification Service http://push.baidu.com/doc/ios/api Google Push Notification Service https://docs.pushio.com/API_&_cURL_Information/Platform_Specific_Payloads/GCM_%28Google_Cloud_Messaging%29 Apple Push Notification Service https://deve

Missing Push Notification Entitlement解决方法

原委 最近提交APP到Apple Store审核,结果很快就收到Apple很"贴心"的邮件.原文如下: Dear developer, We have discovered one or more issues with your recent delivery for "APP Name". Your delivery was successful, but you may wish to correct the following issues in your

资料整理:基于node push server实现push notification

chat example based on ionic/ socket.io/ redis https://github.com/jbavari/ionic-socket.io-redis-chat http://jbavari.github.io/blog/2014/06/17/building-a-chat-client-with-ionic/ socket.io example: http://socket.io/get-started/chat/ how node.js interact

Mobile Push Notification

In one embodiment, a method includes sending to a mobile client computing device a first notification through a real-time push service, the first notification including content and being associated with a stateful object; the method also includes, in

Send push notification on Apple (APNS) on c#.net

原文: http://apns-c-sharp-net-vikram-jain.blogspot.com ======================= Please, Install your certificate *.p12 on pc, and take firend name use here for refernce. Please, set configuration file : <appSettings> <add key="FriendName"