I. Understand push

First, what does an aurora do with a map



Yes, we use its push component to do both online and remote push work.

In daily development, there are three push modes:

  • Local delivery

A way to push through the system notification center rather than through the server and network

  • Remote push

The server is pushed through APNs and displayed in the notification center and lock screen bar

  • Online push

In-app push via long links has nothing to do with the original iOS notification system.


Ii. Certificate setting and creating applications

Step 1:Certificates, IDs&Profiles

The Push Notification function was enabled



The push certificate is generated, and an aos.cer file is obtained



The Profile file is generated

Depending on the push scenario, you can choose to develop and publish files


Step 2: Set Xcode

Replace with the configuration information prepared for push

Open the Push Notification

Check that the bundleID is the same as in the Aurora application


Step 3: Push the application background

Create an application, set authentication, and open the channel between the push and the application

The authentication information can be the same bundleID and cannot be changed. To change the bundleID, contact aurora staff for replacement



There are two authentication modes:

  • This section describes how to import a p12 push certificate for authentication

    Because the production certificate can also be debugged, you can directly import the production certificate without importing the debugging certificate, which avoids the repeated importing operations

  • Use keys->auth key to authorize key authentication

    Select the APNs service in key. Auth key can be used in production and development environments. Since auth key does not expire, it can only be downloaded once and bundleID and teamID are required


Integration of 3.

APNs notification message

Initialize the

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [self initloadAPNs];
    returnYES; } - (void)initloadAPNs { //Required //notice: JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init]; JPUSHRegisterEntity = [[JPUSHRegisterEntity alloc] init]; entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound|JPAuthorizationOptionProvidesAppNotific ationSettings;if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {// Categories // NSSet<UNNotificationCategory *> * Categories can be addedfor iOS10 or later
    // NSSet<UIUserNotificationCategory *> *categories foriOS8 and iOS9 } [JPUSHService registerForRemoteNotificationConfig:entity delegate:self]; } / / < JPUSHRegisterDelegate > / / agreementCopy the code

registered

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {/ / / Required - registered DeviceToken [JPUSHService registerDeviceToken: DeviceToken]; }Copy the code

Registration failure callback

#pragma mark - Failed to register APNs interface
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    //Optional
    NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);
}Copy the code

If the following information is displayed on the console, the system is successfully added

JGPush[569:185430]  | JIGUANG | I - [JIGUANGDeviceTokenReport] upload device token successCopy the code

Obtain the APNs push content

/ / get APNs content callback (iOS7 - iOS10) - (void) application: (UIApplication *) application didReceiveRemoteNotification: (NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { NSLog(@"this is iOS7 Remote Notification"); // Required, iOS 7 Support [JPUSHService handleRemoteNotification:userInfo]; completionHandler(UIBackgroundFetchResultNewData); } / / get APNs content callback (iOS6 and below) - (void) application: (UIApplication *) application didReceiveRemoteNotification: (NSDictionary *)userInfo {// Obtain the APNs standard information NSDictionary *aps = [userInfo valueForKey:@"aps"];
    NSString *content = [aps valueForKey:@"alert"]; NSInteger Badge = [[aps valueForKey:@"badge"] integerValue]; NSString * Sound = [aps valueForKey:@]"sound"]; NSString *customizeField1 = [userInfo valueForKey:@"customizeExtras"]; // The Extras field on the server, key is defined by NSLog(@)"content =[%@], badge=[%d], sound=[%@], customize field =[%@]",content,badge,sound,customizeField1);
    
    // Required, For systems with less than or equal to iOS 6
    [JPUSHService handleRemoteNotification:userInfo];
}
#pragma mark - get APNs content (iOS10 +)// After receiving the notification, // iOS 10 Support - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler { //  Required NSDictionary * userInfo = notification.request.content.userInfo;if(@ the available (iOS 10.0, *)) {if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
            [JPUSHService handleRemoteNotification:userInfo];
        }else{// local notification}}else {
        // Fallback on earlier versions
    }
    if(@ the available (iOS 10.0. *)) {completionHandler (UNNotificationPresentationOptionAlert); // If you need to perform this method, select whether to Alert the user or not. There are three types of Badge, Sound and Alert, you can select the Settings}else{// Fallback on earlier versions}} // iOS 10 Support - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler { // Required NSDictionary * userInfo = response.notification.request.content.userInfo;if(@ the available (iOS 10.0, *)) {if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
            [JPUSHService handleRemoteNotification:userInfo];
        }else{// local notification}}else{ // Fallback on earlier versions } completionHandler(); // The system requires this method to be executed}#pragma mark- JPUSHRegisterDelegate// iOS12 Support - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(UNNotification *)notification{if(@ the available (iOS 10.0, *)) {if(notification && [notification request. The trigger isKindOfClass: [UNPushNotificationTrigger class]]) {/ / from the notification interface directly into application}else{// Enter the application from the notification Settings screen}}else {
        // Fallback on earlier versions
    }
}Copy the code

Note: Another way to get push content

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // apn NSDictionary *remoteNotification = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];return YES;
}Copy the code

JPush custom message

Initialization and registration

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [self initloadJPush];
    returnYES; } appKey Select an application on the Web Portal and click Set to obtain its appKey value. Ensure that the appKey configured in the application is the same as that generated after the application is created on the Portal. Channel specifies the channel from which the App package was downloaded. You can define the value to facilitate channel statistics, such as App Store. ApsForProduction1.3.1 added to identify the APNs certificate environment used by the current application. 0 (default value) indicates that the development certificate is used, and 1 indicates that the production certificate is used to publish applications. Note: The value of this field should be consistent with the certificate environment for the Code Signing configuration in Build Settings. AdvertisingIdentifier See about IDFA for details. - (void) initloadJPush {/ / Required / / start the SDK [JPUSHService setupWithOption: launchOptions appKey: appKey channel: the channel apsForProduction:isProduction]; // Optional // Obtain IDFA // To use the IDFA function, add this code and enter the corresponding value in the advertisingIdentifier parameter NSString *advertisingId = in the initialization method [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]; / / start the SDK, including IDFA method [JPUSHService setupWithOption: launchOptions appKey: appKey channel: the channel apsForProduction: isProduction advertisingIdentifier:advertisingId]; }Copy the code

The console output status, if the following, indicates success

JGPush[562:182045]  | JIGUANG | I - [JIGUANGLogin] 
----- login result -----
uid:5460310207 
registrationID:171976fa8a8620a14a4 
idc:0Copy the code

Get custom push content

- (BOOL) application: (UIApplication *) application didFinishLaunchingWithOptions: (launchOptions NSDictionary *) {/ / registration notice NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter]; [defaultCenter addObserver:self selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil];returnYES; } / / callback - (void) networkDidReceiveMessage: (NSNotification *) notification {NSDictionary * the userInfo = [notification userInfo]; NSString *content = [userInfo valueForKey:@"content"];
   NSString *messageID = [userInfo valueForKey:@"_j_msgid"];
   NSDictionary *extras = [userInfo valueForKey:@"extras"]; 
   NSString *customizeField1 = [extras valueForKey:@"customizeField1"]; // Extras are passed by the server and the key is defined by itself}Copy the code

Cancel the corner label operation

In addition to clearing the local corner operation


You can also manipulate the badge value of the push server

- (void) applicationWillEnterForeground application: (UIApplication *) {/ / program into the front desk, Cancel the number of messages App right corner application. ApplicationIconBadgeNumber = 0; }Copy the code


Iv. Development and production environment debugging

There are two push modes: Web JPush and App Service. Only aurora developer platform push is introduced here.

Aurora push includes notification and custom message.

Sending notification (APNs notification) – In the App foreground and background, and in the exit state, the App can be started by triggering push notification


Custom messaging (JPush) – Push within the App only, i.e. the App must be in the foreground to receive a push message


IOS12 push new features

Added automatic grouping, which pushes groups based on the App’s bundle ID

Thresd Identifier groups different content pushed by an App

The group summary formats the content displayed in the bottom row of the group column. Default: there are n notifications


Vi. Customized push

Geographical fence

Purpose: Select a geofen when pushing multiple conditions. When the phone enters or leaves a certain area, it will receive push notifications.

Follow protocol <JPUSHGeofenceDelegate> to inject geofering methods - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [JPUSHService registerLbsGeofenceDelegate:self withLaunchOptions:launchOptions]; } // After the injection is successful, you need to invoke the proxy method in the protocol to implement the event response after the callbackCopy the code

Use to get tags and aliases

Purpose: In multi-condition push, select different target groups and push different content.

Alias: Identifies a unique user and can be bound to the login user ID to ensure that different accounts can be uniquely pushed.

Tag: Unified push to the user group and type tag. Such as gender, age, hobbies.

RegistrationID: After a successful JPush registration, a registrationID is generated to represent the unique ID of the device. In a given push, the content can be pushed based on the unique ID of the user.

/ / get registrationID label [JPUSHService registrationIDCompletionHandler: ^ (int resCode, nsstrings * registrationID) {NSLog (@"resCode : %d,registrationID: %@",resCode,registrationID);
}];Copy the code



The above is purely personal and I hope I can contribute more to the iOS community.