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-computer-tested profile certificates need to be created manually, as long as the Apple ID is automatically generated and tested for free:
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; If you do not use IDFA, do not add)
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 Year Mac. All rights reserved.//#import<Foundation/Foundation.h>@interfaceKjjpushhelper:nsobject//called when the app is started+ (void) Setupwithoption: (Nsdictionary *) launchingoption AppKey: (NSString*) AppKey Channel: (NSString*Channel apsforproduction: (BOOL) isproduction advertisingidentifier: (NSString*) Advertisingid;//called at the Appdelegate registration device+ (void) Registerdevicetoken: (NSData *) Devicetoken;//after iOS7, only completion, otherwise pass 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 Year Mac. All rights reserved.//#import "KJJPushHelper.h"#import "JPUSHService.h"@implementationKjjpushhelper+ (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//You can customize the category after iOS8 if([[Uidevice currentdevice].systemversion Floatvalue] >=8.0) { //You can add a custom categories[Jpushservice registerforremotenotificationtypes: (Uiusernotificationtypebadge |Uiusernotificationtypesound|Uiusernotificationtypealert) Categories:nil]; } Else {#if__iphone_os_version_max_allowed < __iphone_8_0//iOS8 before the categories must be nil[Jpushservice registerforremotenotificationtypes: (Uiremotenotificationtypebadge |Uiremotenotificationtypesound|Uiremotenotificationtypealert) Categories:nil];#endif }#else //the 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 Year Mac. All rights reserved.//#import "AppDelegate.h"@interfaceappdelegate (KJJPUSHSDK)-(void) Jpushapplication: (uiapplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions;@end//APPDELEGATE+KJJPUSHSDK.M////Created by Mac on 16/5/5.//copyright©2016 Year Mac. All rights reserved.//#import "appdelegate+kjjpushsdk.h"#import "KJJPushHelper.h"#defineJpushsdk_appkey @ "31E01F6A2F6D4B1209061AEC"#defineIsproduction NO@implementationappdelegate (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 {//Required,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[Kjjpushhelper handleremotenotification:userinfo Completion:completionhandler]; //The app is processing foreground status and will not receive push messages, so you need to deal with it here if(Application.applicationstate = =uiapplicationstateactive) {Uialertview*alert =[[Uialertview alloc] Initwithtitle:@"Receive push Messages"message:userinfo[@"APS"][@"Alert"] Delegate: nil Cancelbuttontitle:@"Cancel"Otherbuttontitles:@"Determine", nil]; [Alert show]; }}- (void) Application: (UIApplication *) application Didfailtoregisterforremotenotificationswitherror: (NSError *) Error {//OptionalNSLog (@"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
// sign up for 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.
IOS: Aurora Push