IOS: Aurora Push

Source: Internet
Author: User

Before the ring letter and friends of the push, according to the official document integration is actually quite simple, the company needs today, specifically to do the Aurora push. Do not know, the original Aurora push integration so simple, have to say.

Of course, doing push money needs to do some preparatory work, that is, to push the required P12 push certificate: The development environment (the push certificate required for development testing), the production environment (the push certificate that is required to publish to AppStore), Because Xcode has been upgraded to more than 7.0, some of the real-machine test profile certificates do not need to be created manually, as long as the Apple ID, the real-time test, can be automatically generated, free testing:

The process of making a certificate is not verbose, look at official documents or the following recommendations:

Http://jingyan.baidu.com/article/c1465413975cba0bfcfc4ccf.html

http://docs.jpush.io/client/ios_tutorials/#ios_1

http://docs.jpush.io/guideline/ios_guide/

http://allluckly.cn/Submission/tuogao28?utm_source=tuicool&utm_medium=referral

After the creation of the certificate, is to go to the Aurora website to register an account, create an application, as follows:

The created certificate is uploaded to the app, and the upload succeeds as follows:

Once the certificate has been uploaded successfully, generate the app Key, as follows:

OK, this job is done, the rest is the code implementation:

Step one: Download the SDK and import the two required files into your project:

Integrated Compressed Package Content

Package name is jpush-ios-sdk-{version number}

    • Lib folder: Contains header file JPUSHService.h, static library file jpush-ios-x.x.x.a, supported iOS version 5.0 and later. (Note: Emulator does not support APNs)
    • PDF file: Integration Guide
    • Demo folder: Example

Step Two: Import the library files you need to rely on:

The necessary framework
    • Cfnetwork.framework
    • Corefoundation.framework
    • Coretelephony.framework
    • Systemconfiguration.framework
    • Coregraphics.framework
    • Foundation.framework
    • Uikit.framework
    • Security.framework
    • Xcode7 need is libz.tbd;xcode7 the following version is Libz.dylib
    • Adsupport.framework (get IDFA required; Do not add if IDFA is not used)

Step Three: Create a tool class, named Kjjpushhelper, to encapsulate various methods of registering

. h

  kjjpushhelper.h////  Created by Mac on 16/5/5.//  Copyright? 2016 Mac. All rights reserved.//#import <Foundation/Foundation.h> @interface kjjpushhelper:nsobject//call + (void) when the app starts Setupwithoption: (nsdictionary *) launchingoption                 AppKey: (NSString *) AppKey                Channel: (NSString *) Channel       apsforproduction: (BOOL) isproduction  advertisingidentifier: (NSString *) advertisingid;// Call + (void) Registerdevicetoken at appdelegate registration device: (NSData *) devicetoken;//iOS7, only completion, otherwise nil+ (void) Handleremotenotification: (nsdictionary *) UserInfo Completion: (void (^) (uibackgroundfetchresult)) completion;// Show local notifications at the front + (void) Showlocalnotificationatfront: (uilocalnotification *) notification; @end

. m

kjjpushhelper.m//Created by Mac on 16/5/5.//Copyright? 2016 Mac. All rights reserved.//#import "KJJPushHelper.h" #import "JPUSHService.h" @implementation kjjpushhelper+ (void)  Setupwithoption: (nsdictionary *) launchingoption AppKey: (NSString *) AppKey Channel: (NSString *) Channel apsforproduction: (BOOL) isproduction advertisingidentifier: (NSString *) advertisingid{//required#if _ _iphone_os_version_max_allowed > __iphone_7_1//iOS8 can be customized after the category if ([[Uidevice currentdevice].systemversion Floatvalue] >= 8.0) {//can add custom categories [Jpushservice registerforremotenotificationtypes: (Uiusernotifi                                                          Cationtypebadge |                                                          Uiusernotificationtypesound |    Uiusernotificationtypealert) Categories:nil]; } else {#if __iphone_os_version_max_allowed < __IPHONE_8_0//IOS8 before categories must be nil [jpushservice registerforremotenotificationtypes: (Uiremotenotificationtypebadge |                                                          Uiremotenotificationtypesound |    Uiremotenotificationtypealert) Categories:nil]; #endif} #else                                                      Categories must be nil [jpushservice registerforremotenotificationtypes: (Uiremotenotificationtypebadge |                                                      Uiremotenotificationtypesound |    Uiremotenotificationtypealert) Categories:nil]; #endif//Required [Jpushservice setupwithoption:launchingoption Appkey:appkey Channel:channel apsforproduction:isproduction    Advertisingidentifier:advertisingid]; return;}    + (void) Registerdevicetoken: (NSData *) Devicetoken {[Jpushservice registerdevicetoken:devicetoken]; return;} + (void) Handleremotenotification: (nsdictionary *) UserInfo Completion: (void (^) (Uibackgroundfetchresult)) Completion {[        Jpushservice Handleremotenotification:userinfo];    if (completion) {completion (uibackgroundfetchresultnewdata); } return; + (void) Showlocalnotificationatfront: (uilocalnotification *) notification {[Jpushservice    Showlocalnotificationatfront:notification Identifierkey:nil]; return;} @end

Fourth step: Create a Appdelegate classification that calls the class method in Kjjpushhelper in this class

appdelegate+kjjpushsdk.h////Created by Mac on 16/5/5.//Copyright? 2016 Mac. All rights reserved.//#import "AppDelegate.h" @interface appdelegate (KJJPUSHSDK)-(void) Jpushapplication: ( UIApplication *) Application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions; @end//AppDelegate+ kjjpushsdk.m////Created by Mac on 16/5/5.//Copyright? 2016 Mac. All rights reserved.//#import "Appdelegate+kjjpushsdk.h" #import "KJJPushHelper.h" #define Jpushsdk_appkey @ " 31E01F6A2F6D4B1209061AEC "#define Isproduction no@implementation appdelegate (KJJPUSHSDK)-(void) Jpushapplication: ( UIApplication *) Application didfinishlaunchingwithoptions: (nsdictionary *) launchoptions{[KJJPushHelper Setupwithoption:launchoptions Appkey:jpushsdk_appkey Channel:nil apsforproduction:isproduction Advertisingidentifier:nil];} -(void) Application: (UIApplication *) application Didregisterforremotenotificationswithdevicetoken: (NSData *) Devicetoken {//Required-register Devicetoken [Kjjpushhelper reGisterdevicetoken:devicetoken];} -(void) Application: (UIApplication *) application didreceiveremotenotification: (Nsdictionary *) UserInfo {//Require D,for systems with less than or equal to iOS6 [Kjjpushhelper handleremotenotification:userinfo completion:nil];} -(void) Application: (UIApplication *) application didreceiveremotenotification: (nsdictionary *) userInfo Fetchcompletionhandler: (void (^) (uibackgroundfetchresult)) Completionhandler {//IOS 7 support Required [Kjjpush        Helper Handleremotenotification:userinfo Completion:completionhandler];  The app is processing foreground state and will not receive a push message, so there is an additional need to handle the IF (application.applicationstate = = uiapplicationstateactive) {Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "received push message" message:u                              serinfo[@ "APS"][@ "alert"] Delegate:nil cancelbuttontitle:@ "Cancel"    otherbuttontitles:@ "OK", nil];    [Alert show]; }}-(void) Application: (UIApplication *) application Didfailtoregisterforremotenotificationswitherror: (NSError *) Error {//optional NSLog (@ "did Fail to Register for Remote notifications with error:%@", error);} -(void) Application: (UIApplication *) application didreceivelocalnotification: (uilocalnotification *) Notification {[    Kjjpushhelper Showlocalnotificationatfront:notification]; return;}    -(void) Applicationdidbecomeactive: (uiapplication *) application {[Application setapplicationiconbadgenumber:0]; return;} @end

Fifth step: Register in Appdelegate

Register Aurora push [self jpushapplication:application didfinishlaunchingwithoptions:launchoptions];

All right, all done, plug in the real machine. Run: Print results as follows

Go to the official website to test:

The real machine receives the message:

Integration process encountered problems, troubled for a long time, and later found out, to share a bit:

There was no problem with the certificate at the time, but this printing always appeared:

Error message Jpush | W-[Jpushclientcontroller] not get devicetoken yet. Maybe:your certificate Not configured APNs? is the or current network isn't so good so APNs registration failed? Or there is no APNs register code? Refer to Jpush Docs.

When you push a message, the prompt appears:

My reason is:

Since the project was preceded by the Ring letter SDK, the ring letter has been registered notice, registered in the appdelegate notice, Didregisterforremotenotificationswithdevicetoken and Didfailtoregisterforremotenotificationswitherror methods are not performed ... To register notice of the ring letter, register the Aurora notice again. The party can obtain the token execution.

Extension: Directional push in Aurora push

Aurora Push, do not use broadcast push, then how to do the directional push, is the developer and demand will certainly appear, the Aurora push can have two unique values:

(1) Registered Jpush after the successful generation of Registrationid, the Registrationid is the uniqueness of the tag device, you find that when you start multiple times, registered Jpush, this value is unchanged; On the same device, the replacement user login, this value is still unchanged; Finally, you delete the application and then start the registration Jpush when you download it, the value remains the same. This can be directed to a device to push, if you can upload this value to your own server, and to give this value to bind some things, is it possible to do more things.

(2) Alias: As long as the Aurora push knows that this is a set alias, the official document shows that this value is not unique, but it is recommended that the developer as the user's unique tag. I think this is best as a unique value, which is great when you want to direct a push to a user, or call him back to our app. You can set it to UserID, and at this point the push will know which user to send it to.

IOS: Aurora Push

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.