"Go" IOS message push implementation process record

Source: Internet
Author: User

Client code: Link Address

Server code: Link Address link address

The whole process of iOS message push implementation is recorded here

First, apply for the secret key.

Then enter the link address developer, of course you have to have AH!!!!!

Click here

The following implementation creates a push certificate (not the same as the development certificate)

Pick up:

The first step is complete:

To add push functionality to a certificate:

Post-click Effects:

After clicking

By now we have two certificates, Aps_development.cer and Certificatesigningrequest.certsigningrequest.

The following steps are more critical. We need to clean up the previous certificate in the machine, and if we don't clean the picture, the following error will appear:

Error domain=nscocoaerrordomain code=3000 " The "aps-environment" right string for the application was not found "userinfo=0x17007d6c0 {nslocalizeddescription= The "aps-environment" right string for the application was not found}

This error probably means that the certificate does not match.

After cleaning, we click

Add the push certificate in.

Open the push notifications switch in the capabilities
In the XCode7 here the switch does not open, push also can be normal use, but in XCode8, here the switch must open, otherwise will error:

Error Domain=NSCocoaErrorDomain Code=3000 "未找到应用程序的“aps-environment”的授权字符串" UserInfo={NSLocalizedDescription=未找到应用程序的“aps-environment”的授权字符串}

After that we export a server-side for use.

The following code is a contribution to live Lei Feng online.

The following is the client code:

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions{//Override point for customization after application launch.NSString* str =[Uidevice Currentdevice]; if([launchoptions objectforkey:uiapplicationlaunchoptionsremotenotificationkey]! =Nil) {        //gets the number of application message notification tokens (that is, the number in the small red circle)        intBadge =[UIApplication Sharedapplication].applicationiconbadgenumber; if(badge>0) {            //if the number of application message notification tokens (that is, the number in the small red circle) is greater than 0, clear the marker. badge--; //clears the tag. Clear the small red circle in the number, the small red circle in the number of 0, the small red circle will be eliminated. [UIApplication Sharedapplication].applicationiconbadgenumber =badge; }    }    //Message Push Registration[[UIApplication Sharedapplication] registerforremotenotificationtypes:uiremotenotificationtypesound| Uiremotenotificationtypealert|Uiremotenotificationtypebadge]; returnYES;}-(void) Application: (UIApplication *) application Didregisterforremotenotificationswithdevicetoken: (NSData *) devicetoken{NSString* token = [NSString stringWithFormat:@"%@", Devicetoken]; NSLog (@"%@", token); }- (void) Application: (UIApplication *) application Didfailtoregisterforremotenotificationswitherror: (NSError *) Error {NSString*ERROR_STR = [NSString stringWithFormat:@"%@", error]; NSLog (@"Failed to get token, error:%@", ERROR_STR);}- (void) Application: (UIApplication *) Applicationdidreceiveremotenotification: (Nsdictionary*) userinfo{//the received message is processed here. NSLog (@"Receive Remote notification:%@", UserInfo);}

The server-side code is attached below:

import Org.apache.log4j.logger;import org.apache.log4j.propertyconfigurator;import Javapns.*; import Javapns.back.pushnotificationmanager;import Javapns.back.sslconnectionhelper;import Javapns.data.device;import Javapns.data.PayLoad; Public classPushdemo { Public Static voidMain (string[] args) throws Exception {Try            {                //The Devicetoken obtained from the client, in order to test the simple, write a fixed test device identity. String Devicetoken ="9f8e0099 1e72c4ab ca835ec3 994e93d9 a09ce215 62d91bb3 6e929a33 02c29456"; System. out. println ("Push Start Devicetoken:"+Devicetoken); //Defining message PatternsPayLoad PayLoad =NewPayLoad (); Payload.addalert ("This is test!"); Payload.addbadge (1);//the number of message push marks, the number shown in the small red circle. Payload.addsound ("default"); //Register DevicetokenPushnotificationmanager Pushmanager =pushnotificationmanager.getinstance (); Pushmanager.adddevice ("IPhone", Devicetoken); //Connection APNsString host ="gateway.sandbox.push.apple.com"; //String host = "gateway.push.apple.com";                intPort =2195; String Certificatepath="/USERS/TOKOU/DESKTOP/PUSHDEMO.P12";//The *.p12 file location for the Java background Connection APNs service generated earlierString Certificatepassword ="123";//p12 file password. pushmanager.initializeconnection (host, Port, Certificatepath, Certificatepassword, Sslconnectionhelper .                KEYSTORE_TYPE_PKCS12); //Send PushDevice client = Pushmanager.getdevice ("IPhone"); System. out. println ("Push message:"+ Client.gettoken () +"\ n"+payload.tostring () +" ");                Pushmanager.sendnotification (client, payLoad); //Stop Connection APNspushmanager.stopconnection (); //Delete DevicetokenPushmanager.removedevice ("IPhone"); System. out. println ("Push End"); }            Catch(Exception ex) {ex.printstacktrace (); }    }}

Original address: http://www.aiuxian.com/article/p-1327006.html

"Go" IOS message push implementation process record

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.