Li Hongqiang iOS integrated Aurora push three iOS integration guide

Source: Internet
Author: User

Li Hongqiang iOS integrated Aurora push three iOS integration guide

SDK Description Applicable version

This article matches the SDK version: r2.1.5 later.
See recent updates for the latest SDK updates.
Using Xcode 6 and later, you can use the new push Sdk,xcode 5 environment to run an older version of the SDK (1.7.4)

Resource file

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

    • Lib folder: Contains header file JPUSHService.h, static library file jpush-ios-x.x.x.a,jcore-ios-x.x.x.a, supported iOS version 6.0 and later. (Note: Emulator does not support APNs)
    • PDF file: Integration Guide
    • Demo folder: Example
Create an App
    • Create an app on Jpush's management portal and upload the APNs certificate. If you are not familiar with the APNs certificate, please refer to: IOS Certificate Setup Guide

    • The AppKey is automatically generated after a successful creation to identify the app.

Configure the Project Import SDK

Select 1:cocoapods Import

    • by Cocoapods:
pod ‘JPush‘
    • If you need to install the specified version, use the following method (for example, version 3.0.2):
pod ‘JPush‘, ‘3.0.2‘

Option 2: Import manually

    • Download the latest SDK on the Aurora website
    • Unzip the SDK package, select "Add files to ' Your project name ' ..." in Xcode, and the Unpacked Lib subfolder (contains JPUSHService.h, JPUSH-IOS-X.X.X.A, JCORE-IOS-X.X.X.A) is added to your project directory.
    • Add Framework
      • Cfnetwork.framework
      • Corefoundation.framework
      • Coretelephony.framework
      • Systemconfiguration.framework
      • Coregraphics.framework
      • Foundation.framework
      • Uikit.framework
      • Security.framework
      • LIBZ.TBD (Xcode7 The following version is Libz.dylib)
      • Adsupport.framework (get IDFA required; Do not add if IDFA is not used)
      • Usernotifications.framework (Xcode8 and above)
      • LIBRESOLV.TBD (Jpush 2.2.0 and above required, Xcode7 the following version is Libresolv.dylib)

Note: If integrated Jpush 3.0.1 and above, and integrated Aurora other SDK (e.g. Jmessage 3.0.0 and above)
1. Cocoapods import, it is recommended to update to the latest online version to avoid conflicts caused by Jcore version inconsistencies.
2. Manual import, in the project only need to keep a latest version of the JCORE-IOS-X.X.X.A static library files.

Build Settings

If your project needs to support iOS systems less than 7.0, go to build Settings to turn off the bitcode option, otherwise it will not compile properly.

    • Set the User Header search Paths and the library search Paths under Search Paths, such as the SDK folder (the default is Lib) and the project file in the same level directory, are set to "$ (srcroot)/{the file where the static library resides Folder name} ".
Capabilities

If using XCODE8 and above environment development, please open application Target's capabilities->push notifications option,

Allow Xcode7 to support HTTP transfer methods

You do not need to configure this step if you are using a version of 2.1.9 and above
If you are using Xcode7 or later, you need to manually configure the key and value in the plist of the app project to support HTTP transport:

Option 1: According to the domain name configuration

    • Add a key:nsapptransportsecurity to the info.plist of the project, and the type is the dictionary type.
    • Then add a nsexceptiondomains to it, the type is the dictionary type;
    • Add the required supported domains to the nsexceptiondomains. Where jpush.cn is the key, the type is the dictionary type.
    • You need to set 2 properties under each domain: Nsincludessubdomains, nsexceptionallowsinsecurehttploads. All two properties are of type Boolean, with a value of Yes and yes respectively.

Option 2: Global configuration

  <key>NSAppTransportSecurity</key>   <dict>     <key>NSAllowsArbitraryLoads</key>     <true/>   </dict>            
Add header File

Please add the following code to the location of the APPDELEGATE.M reference header file.

// 引入JPush功能所需头文件#import "JPUSHService.h"// iOS10注册APNs所需头文件#ifdef NSFoundationVersionNumber_iOS_9_x_Max#import <UserNotifications/UserNotifications.h>#endif// 如果需要使用idfa功能所需要引入的头文件(可选)#import <AdSupport/AdSupport.h>
Add delegate

Add delegate for Appdelegate.

Reference code:

@interface AppDelegate ()<JPUSHRegisterDelegate>@end
Adding initialization code

Starting with the 2.1.0 version, the API class is named Jpushservice and no longer uses the original apservice.

Adding initialization APNs Code

Please add the following code to the
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions

  //Required  //notice: 3.0.0及以后版本注册可以这样写,也可以继续用之前的注册方式  JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];  entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound;  if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {    // 可以添加自定义categories    // NSSet<UNNotificationCategory *> *categories for iOS10 or later    // NSSet<UIUserNotificationCategory *> *categories for iOS8 and iOS9  }  [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
Adding initialization Jpush Code

Please add the following code to the
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions

  // Optional  // 获取IDFA  // 如需使用IDFA功能请添加此代码并在初始化方法的advertisingIdentifier参数中填写对应值  NSString *advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];  // Required  // init Push  // notice: 2.1.5版本的SDK新增的注册方法,改成可上报IDFA,如果没有使用IDFA直接传nil  // 如需继续使用pushConfig.plist文件声明appKey等配置内容,请依旧使用[JPUSHService setupWithOption:launchOptions]方式初始化。  [JPUSHService setupWithOption:launchOptions appKey:appKey                        channel:channel               apsForProduction:isProduction          advertisingIdentifier:advertisingId];  
Some parameter description:
    • AppKey
      • Fill out the Appkey values that are automatically generated when the app is created on the management portal. Make sure that the AppKey in-app configuration is consistent with the AppKey generated after the app is created on the Portal.
    • Channel
      • Specifies the download channel for the application package, which is defined by you, such as the app Store, for ease of channel statistics.
    • Apsforproduction
      • The 1.3.1 version is new to identify the APNS certificate environment used by the current app.
      • 0 (the default) indicates that a development certificate is used and 1 means that the application is published with a production certificate.
      • Note: The value of this field is consistent with the certificate environment configured for the code signing of build settings.
    • Advertisingidentifier
      • See About IDFA.
Register APNs Success and report Devicetoken

Implement the callback method in APPDELEGATE.M and add the code in the callback method

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {  /// Required - 注册 DeviceToken  [JPUSHService registerDeviceToken:deviceToken];}
Implement registration APNs failed interface (optional)
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {  //Optional  NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);}
Add process APNs Notification callback method

Implement the callback method in APPDELEGATE.M and add the code in the callback method

#pragma mark-jpushregisterdelegate//IOS support-(void) Jpushnotificationcenter: (Unusernotificationcenter *) Center willpresentnotification: (unnotification *) notification Withcompletionhandler: (void (^) (Nsinteger))  Completionhandler {//Required nsdictionary * userInfo = notification.request.content.userInfo; if ([Notification.request.trigger Iskindofclass:[unpushnotificationtrigger class]]) {[Jpushservice  Handleremotenotification:userinfo]; } completionhandler (Unnotificationpresentationoptionalert); Need to execute this method, choose whether to remind the user, there are badge, sound, alert three types can choose to set}//IOS support-(void) Jpushnotificationcenter: ( Unusernotificationcenter *) Center didreceivenotificationresponse: (unnotificationresponse *) response Withcompletionhandler: (void (^) ()) Completionhandler {//Required nsdictionary * userInfo = Response.notification.reque  St.content.userInfo; if ([Response.notification.request.trigger Iskindofclass:[unpushnotificationtrigger class]]) {[Jpushservice Handleremotenotification:userInfo];  } completionhandler (); The system requires that this method be executed}-(void) Application: (UIApplication *) application didreceiveremotenotification: (Nsdictionary *) UserInfo Fetchcompletionhandler: (void (^) (uibackgroundfetchresult)) Completionhandler {//Required, IOS 7 support [Jpus  Hservice Handleremotenotification:userinfo]; Completionhandler (uibackgroundfetchresultnewdata);} -(void) Application: (UIApplication *) application didreceiveremotenotification: (Nsdictionary *) UserInfo {//Required, For systems with less than or equal to iOS6 [Jpushservice handleremotenotification:userinfo];}
Adding a callback method for handling Jpush custom messages

To use the custom message feature of Jpush, refer to the documentation to implement the handling callback method for the custom message.

Run successfully

Real-Time debugging the project, if the console output the following log indicates that you have successfully integrated.

2016-08-19 17:12:12.745823 219b28[1443:286814]  | JPUSH | I - [JPUSHLogin] ----- login result -----  uid:5460310207   registrationID:171976fa8a8620a14a4  

If you are having trouble debugging, please refer to: IOS SDK Debugging Guide

Advanced Features about IDFA

r2.1.5 version adds an interface to upload IDFA strings

 + (void)setupWithOption:(NSDictionary *)launchingOption                  appKey:(NSString *)appKey                 channel:(NSString *)channel        apsForProduction:(BOOL)isProduction   advertisingIdentifier:(NSString *)advertisingId;

If you do not use IDFA, you can still use the interface

+ (void)setupWithOption:(NSDictionary *)launchingOption                  appKey:(NSString *)appKey                 channel:(NSString *)channel        apsForProduction:(BOOL)isProduction;
Jpush SDK related Event monitoring

Developers are advised to include the following types of notifications in the API:

extern nsstring *const kjpfnetworkisconnectingnotification; Connecting in progress

extern NSString * Const kjpfnetworkdidsetupnotification; Establish a connection

extern NSString * Const kjpfnetworkdidclosenotification; Close connection

extern NSString * Const kjpfnetworkdidregisternotification; Registration successful

extern nsstring *const kjpfnetworkfailedregisternotification; Registration failed

extern NSString * Const kjpfnetworkdidloginnotification; Login successful

Warm tips:

The registration ID needs to be added to the method of registering the Kjpfnetworkdidloginnotification notification, or the [Registrationidcompletionhandler:] method can be called, Get through Completionhandler

extern NSString * Const kjpfnetworkdidreceivemessagenotification; Receive custom messages (non-APNS)

The data passed by Kjpfnetworkdidreceivemessagenotification can be obtained by userinfo method in Nsnotification, including title, content, extras information, etc.

Li Hongqiang iOS integrated Aurora push three iOS integration guide

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.