Integration and considerations for iOS Aurora push

Source: Internet
Author: User

Turn from: https://www.jianshu.com/p/1d37efd7d65c


now, we start by creating a good Aurora application, and after we get Appkey, open the Xcode, enter the project, as shown in the diagram, you can see a switch, push notifications

Notification switch
After the switch is turned on, a project name, entitlements file is generated.
Entitlements.png

but before that, a lot of people didn't push the notificaitons switch, don ' t worry, go into the Aurora homepage, you'll find that you need to import a variety of dependent library dependencies. png

We add a dependency library to the build phases under Xcode, such as figure build phases

After importing a dependent library, the most critical repository here is Usernotificationcations.framework (Xcode8 and above), close the program, reboot, switch on, and then turn on the switch, as shown in Figure Push notifications Under the switch, steps has two items, the first if red, the certificate and the configuration file (that is, the certificate and the configuration file generated in Apple Developer) are not imported; if the second burst red, it may be because you accidentally deleted the Project name. Entitlements file, the solution is to close the push notifications switch and then open to generate, if not, close the program, the switch can be turned off, if not again, go to your trash inside to find you deleted Project name. Entitlements file, drag back to project to restart Project

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 (default Lib) and the project file in the same level directory, then set to "$ (srcroot)/{Static library file Folder name} ". From the Aurora document

2. Allow Xcode7 to support HTTP transmission methods

You do not need to configure this step if you are using 2.1.9 and more versions
If you are using a Xcode7 or newer version, you need to manually configure the keys and values in the app Project plist to support HTTP transmission:
Option 1: Configure by Domain name
Adds a key:nsapptransportsecurity to the info.plist of the project, with a type of dictionary type.
Then add a nsexceptiondomains to it, the type is a dictionary type;
Add the required supported domains to the nsexceptiondomains. Where jpush.cn as key, the type is a dictionary type.
You need to set 2 properties below each domain: Nsincludessubdomains, nsexceptionallowsinsecurehttploads. All two properties are Boolean, and the values are yes, yes. "From the Aurora document." If the figure Snip20161024_10.png configured above, enter the project Appdelegate inside, first import the header file and follow the agent

#import "AppDelegate.h"
#import "JPUSHService.h"
#ifdef nsfoundationversionnumber_ios_9_x_max
#import <UserNotifications/UserNotifications.h>
#endif

@interface appdelegate () <jpushregisterdelegate >
in the System method applies the notice permission, here the highest only applies to xcode8.1 (iOS10.1.2), later if appears iOS11 in makes the renewal change
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {if ([ Uidevice currentdevice].systemversion Floatvalue] >= 10.0) {jpushregisterentity * entity = [[Jpushregisterenti
        Ty Alloc] init]; Entity.types = unauthorizationoptionalert| unauthorizationoptionbadge|
        Unauthorizationoptionsound;
    [Jpushservice registerforremotenotificationconfig:entity delegate:self]; else if ([[Uidevice currentdevice].systemversion Floatvalue] >= 8.0) {//can add custom categories [Jpush
                                                          Service registerforremotenotificationtypes: (Uiusernotificationtypebadge |
                                                          Uiusernotificationtypesound |
    Uiusernotificationtypealert) Categories:nil]; else {//categories must be nil [jpushservice registerforremotenotificationtypes: (UiremotenotifiCationtypebadge |
                                                          Uiremotenotificationtypesound |
    Uiremotenotificationtypealert) Categories:nil]; } [Jpushservice setupwithoption:launchoptions appkey:appkey Channel:channel APs  Forproduction:isproduction Advertisingidentifier:nil]; Here is no advertisingidentifier situation, there are words that everyone in themselves Add//register remote message notification get device token [application registerforremotenotifications]
;
 }

Note: Appkey must not forget to copy from the Aurora to get Devicetoken .

Get Devicetoken
-(void) Application: (UIApplication *) application Didregisterforremotenotificationswithdevicetoken: (NSData *) devicetoken
{
    [jpushservice Registerdevicetoken:devicetoken];
}
//iOS support received notification at reception
iOS support received notification at reception
-(void) Jpushnotificationcenter: (Unusernotificationcenter *) Center Willpresentnotification: (unnotification *) notification Withcompletionhandler: (void (^) (Nsinteger)) Completionhandler
{
    nsdictionary * userInfo = notification.request.content.userInfo;
    if ([Notification.request.trigger Iskindofclass:[unpushnotificationtrigger class]]) {
        [jpushservice Handleremotenotification:userinfo];
Add a variety of requirements ...
    }
    Completionhandler (Unnotificationpresentationoptionalert); 
In the foreground, add requirements, usually pop-up alert to interact with the user, this time Completionhandler (Unnotificationpresentationoptionalert) This sentence can be commented out, This is the system alert, shown at the top of the app,
}
    * * If you need to customize the frame or pop-up alert at the front desk, you can look at the HTTP://WWW.JIANSHU.COM/P/D2A42072FAD9 article
//IOS Support Click Handle Events
IOS Support Click Processing Event-(void) Jpushnotificationcenter: (Unusernotificationcenter *) Center Didreceivenotificationresponse: (unnotificationresponse *) response Withcompletionhandler: (void (^) ())
    Completionhandler {//Required nsdictionary * userInfo = response.notification.request.content.userInfo; if ([Response.notification.request.trigger Iskindofclass:[unpushnotificationtrigger class]]) {[Jpushservice hand
        Leremotenotification:userinfo]; Push Open if (userInfo) {//Get APNS Standard Information content//Nsdictionary *aps = [UserInfo valuefork
ey:@ "APS"]; NSString *content = [APS valueforkey:@ "alert"]; Push the displayed content//Nsinteger badge = [[APS valueforkey:@ "badge"] integervalue]; Badge quantity//NSString *sound = [APs valueforkey:@ "Sound"];
        
        Play the sound//Add a variety of requirements ....
        [Jpushservice Handleremotenotification:userinfo];
Completionhandler (Uibackgroundfetchresultnewdata);    } completionhandler ();
 System requires this method to be executed}
//IOS7 and above received notification
-(void) Application: (UIApplication *) application didreceiveremotenotification: (nsdictionary *) userInfo Fetchcompletionhandler: (void (^) (uibackgroundfetchresult)) Completionhandler {
    
    //Required, IOS 7 Support
    [ Jpushservice Handleremotenotification:userinfo];
    Completionhandler (Uibackgroundfetchresultnewdata);
}

Here in IOS7 and above system method, if need to do different processing in foreground and backstage, need to judge the state of the app, judge the way as follows

if ([uiapplication sharedapplication].applicationstate = = uiapplicationstateactive) {
        
        //at foreground, add various requirements code ....

    }else if ([uiapplication sharedapplication].applicationstate = = Uiapplicationstatebackground)
    {
        //app In the background, add a variety of requirements
    }
then the problem comes, the front desk received the push method has, there is a situation ... When the program exits completely, in this case, clicking on the notification will take the following approach (that is, the method of registering the notification, the entry of the program)
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions{
}

In this method, we need to determine whether the program is in full exit state, the following methods of judging

Nsdictionary *remotenotification = [Launchoptions Objectforkey:uiapplicationlaunchoptionsremotenotificationkey];
   
    if (remotenotification)
    {

   //program completely exits, click Notice, add Requirements ...

  }
# need attention:
There may be some small partners in the integration process with IOS10 mobile phone test,
in the push notification IOS10 and IOS7 two agent methods are gone, specific reasons for specific treatment, if the
problem is not found, Here are two methods, one: Add the following statement to the end of the Ios10 two proxy methods
#ifdef nsfoundationversionnumber_ios_9_x_max 
#endif      // Ios10 add these two sentences to the
iOS7 proxy method to add the following statements
#if __iphone_os_version_max_allowed > __iphone_7_1  
#endif   Add these two sentences in iOS7 the
second method is to add a judgment directly to the iOS7 proxy method:
if ([[Uidevice currentdevice].systemversion Floatvalue] < 10.0)
//Based on iOS 6 and below system version receive notification
Based on iOS 6 and below, this function will be invoked if the app is in the foreground or when the notification bar is clicked. and whether the program is run in the foreground can be judged by the appdelegate applicationstate. This situation is handled in this function:
-(void) Application: (UIApplication *) application didreceiveremotenotification: (Nsdictionary *) UserInfo {
    //required,for systems with less than or equal to iOS6
    
    //IOS less than 10 Required
     [Jpushservice HandleR Emotenotification:userinfo];
}
//Finally clear the corner mark
-(void) Applicationdidenterbackground: (uiapplication *) application {
    [[UIApplication alloc] SETAPPLICATIONICONBADGENUMBER:0];
}

After clicking Badge 0
-(void) Applicationwillenterforeground: (uiapplication *) application {
    
    [application SETAPPLICATIONICONBADGENUMBER:0];
    [[Unusernotificationcenter alloc] removeallpendingnotificationrequests];
}
Other Features: 1. In the background to different values, click on the notice to enter a different interface, the official website of the Aurora to send a notification interface, expand the optional settings, use additional fields, here I added a key value to the key and value can be set, and then in the project needs to be judged,Set additional fields

The code is as follows: You can call this method in the way you click on the notification.

Incoming fields, changing requirements by field-(void) Extrasofnotificationwithuserinfo: (Nsdictionary *) UserInfo {if (userInfo) {//Get
APNs Standard Information content//Nsdictionary *aps = [UserInfo valueforkey:@ "APS"]; NSString *content = [APS valueforkey:@ "alert"]; Push the displayed content//Nsinteger badge = [[APS valueforkey:@ "badge"] integervalue]; Badge quantity//NSString *sound = [APs valueforkey:@ "Sound"]; Play the sound//Get extras field content nsstring *customizefield1 = [userInfo valueforkey:@ "key"];
            Extras field in service end, key is defined by itself and needs to be consistent with the additional field of Aurora//If the value of the incoming field is 1, enter the corresponding page if ([customizeField1 integervalue] = = 1) {
            Is pushed open uistoryboard *SB = [Uistoryboard storyboardwithname:@ "Main" bundle:nil];
            MAINTABBARVC *roottabbarc = [sb instantiateviewcontrollerwithidentifier:@ "MAINTABBARVC"];
[UIApplication sharedapplication].delegate.window.rootviewcontroller = Roottabbarc;
        The following methods are encapsulated in their own [Roottabbarc Entertoelectronicinvoice];
   } }
    
}
 
Note: The jump method here may not be applicable to all items, you can look at the link below, you may be able to find a suitable for your project jump method
2. Designated users to send remote notification, where the designated user can not only according to Devicetoken to send, in the Aurora's official website also has no option to use Devicetoken to send, the following figureAurora sends messages to target the crowd

Here the registration ID is not devicetoken, say not much, the following we introduce a way to use aliases alias, we know that the designated user sent, but is already registered with the company account of the people, you want to give different people push different messages, Then we specify the user, in fact, based on the user's registered account in our company to send specific messages, such as the user's billing status, etc., so we can after the user login account, to assign a user ID to be used as a unique indicator, binding the Aurora alias or tag, Of course, this binding alias or tag can be discussed with the background, with what is actually possible, the code is as follows

[Jpushservice settags:nil alias:USER_INFO.userID fetchcompletionhandle:^ (int irescode, Nsset *itags, NSString *ialias) {
                NSLog (@ "Setting Result:%i user alias:%@", Irescode,user_info.userid);
This is the method provided by Aurora, User_info.userid is the user ID, you can set according to the account number or other, as long as the guarantee only can


//Don't forget to empty the alias after the logout
[Jpushservice Settags:nil alias:@ "" fetchcompletionhandle:^ (int irescode, Nsset *itags, NSString *ialias) {
        NSLog (@ "Set result:%i user alias:%@", Irescode,user_info.userid);
    }];

After the alias is bound, the task that specifies that the user sends the message can be handed back to the background. If you want to test it yourself, print the User_info.userid and push yourself with the Aurora, as shown by your own alias.

So far, the integration of iOS Aurora push is simply here, not finished ... Cond... Feel good, just point a praise, there are problems can DMS me, or add me qq:1162719523, and disagree that don't know

iOS received a remote notification, pop-up prompt box, click OK to jump to the message interface: HTTP://WWW.JIANSHU.COM/P/D2A42072FAD9


The following comes from: http://blog.csdn.net/qq_26300747/article/details/78454758

The request for a push certificate is no longer being repeat.
After downloading the Aurora push packages, drag them directly into the project to use.
Insert the following code in the Appdelegate

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {[
    Application setapplicationiconbadgenumber:0];

    [Application cancelalllocalnotifications];
    jpushregisterentity * entity = [[Jpushregisterentity alloc] init]; Entity.types = jpauthorizationoptionalert| jpauthorizationoptionbadge|
    Jpauthorizationoptionsound; if ([[[[Uidevice currentdevice].systemversion Floatvalue] >= 8.0) {//can add custom categories//Nsset<unno Tificationcategory *> *categories for iOS10 or later//Nsset<uiusernotificationcategory *> *categories F

    or IOS8 and iOS9} [Jpushservice registerforremotenotificationconfig:entity delegate:self]; [Jpushservice setupwithoption:launchoptions Appkey:appkey Channel:channel APSFO

    Rproduction:isproduction Advertisingidentifier:nil];
return YES; }-(void) Application: (UIApplication *) Application DidregistErforremotenotificationswithdevicetoken: (NSData *) Devicetoken {///Required-register Devicetoken [[Nsuserdefaults STA

    Ndarduserdefaults] setobject:@{@ "DeviceType": @ "IOS", @ "Devicetoken":d Evicetoken} forkey:@ "Devieceinfo"];
[Jpushservice Registerdevicetoken:devicetoken]; }-(void) Application: (UIApplication *) application Didfailtoregisterforremotenotificationswitherror: (NSError *)

Error {//optional NSLog (@ "did Fail to Register for Remote notifications with error:%@", error);} 
-(void) Didreceivejpushnotification: (nsdictionary *) notidict{//Here uniformly handles receiving notifications, notidict all data received}////IOS Support -(void) Jpushnotificationcenter: (unusernotificationcenter *) Center willpresentnotification: (unnotification *) Notification Withcompletionhandler: (void (^) (Nsinteger)) Completionhandler {nsdictionary * userInfo = Notification.req

    Uest.content.userInfo; Unnotificationrequest *request = notification.request; Received push request unnotificationcontent *content = Request.content;  Received the push message content nsnumber *badge = Content.badge;    The angle of the push message nsstring *body = content.body;  Push message body unnotificationsound *sound = content.sound;  The sound of the push message nsstring *subtitle = Content.subtitle;  The subtitle of the push message nsstring *title = Content.title;  The title of the push message if ([Notification.request.trigger Iskindofclass:[unpushnotificationtrigger class]]) {[Jpushservice
        Handleremotenotification:userinfo];
        NSLog (@ "IOS10 reception received remote notification:%@", [self logdic:userinfo]);
    [Self didreceivejpushnotification:userinfo]; else {//judge for local notification NSLog (@ "IOS10 reception received local notification: {\nbody:%@,\ntitle:%@,\nsubtitle:%@,\nbadge:%@,\nsound:%@,\
        nuserinfo:%@\n} ", Body,title,subtitle,badge,sound,userinfo);
    [Self didreceivejpushnotification:userinfo]; } completionhandler (Unnotificationpresentationoptionsound); This method is required to select whether to remind the user that there are badge, Sound, alert three types that can be set up//////IOS Support-(void) Jpushnotificationcenter: ( Unusernotificationcenter *) Center DidreceivenotiFicationresponse: (unnotificationresponse *) response Withcompletionhandler: (void (^) (void) Completionhandler {
    Nsdictionary * UserInfo = response.notification.request.content.userInfo; Unnotificationrequest *request = response.notification.request; Received the push request unnotificationcontent *content = request.content; Received the push message content nsnumber *badge = contents
Related Article

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.