iOS remote push

Source: Internet
Author: User
<span id="Label3"></p><p><p>I. APNS REMOTE PUSH</p></p><p><p>1. All Apple devices, in the networked state, will establish a long connection with the Apple Server.</p></p><p><p>2. Long connection: The connection is established as long as the network is Connected.</p></p><p><p>3. Function of long connection: time calibration, system upgrade, Find My Iphone.</p></p><p><p>4. Benefits of long connection: fast data transfer and the latest Status.</p></p><p><p>5. The Devicetoken processing process is as follows:</p></p><pre class="brush:objc;gutter:true;"><pre class="brush:objc;gutter:true;">1. Mobile Registration remote notification to the APNS server. the 2.APNS server returns devicetoken.3 to your PHONE. the phone then sends Devicetoken to your app.4. your app sends Devicetoken to the data provider.</pre></pre><p><p>6. The process for obtaining devicetoken requires the following files:</p></p><pre class="brush:objc;gutter:true;"><pre class="brush:objc;gutter:true;">1. Computer real-machine Debug Certificate (development certificate or publishing certificate). 2. The uuid.3.appid of the device requires the bundle identifier, which is xcode, must be the full name, can not be replaced by the * number, such as com.ling.identifier4. computer profile (certificatesigningrequest.certsigningrequest file).<br>5. Develop push certificates and publish push Certificates.</pre></pre><p><p>7. Push</p></p><pre class="brush:objc;gutter:true;"><pre class="brush:objc;gutter:true;">Pushmebady is an Open-source mac project for testing Apns. Github:https://github.com/stefanhafeneger/pushmebaby</pre></pre><p><p>8.APNS Push Overall process</p></p><pre><span style="color: #800080;"><span style="color: #800080;">1</span></span><span style="color: #000000;"><span style="color: #000000;">. Create a push-related Certificate.<br> <br></span></span><span style="color: #800080;"><span style="color: #800080;">2</span></span><span style="color: #000000;"><span style="color: #000000;">to invoke the Register remote notification in the start Appdelegate method</span></span><span style="color: #008000;"><span style="color: #008000;">/*</span></span><span style="color: #008000;"><span style="color: #008000;">the 2nd app has been turned off (the process is dead) to launch the app, and the following method of calling Appdelegate is started</span></span><span style="color: #008000;"><span style="color: #008000;">*/</span></span>-(BOOL) application: (uiapplication *) application didfinishlaunchingwithoptions: (nsdictionary *<span style="color: #000000;"><span style="color: #000000;">) launchoptions {</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Override point for customization after application Launch. </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Registration of remote notifications, iOS8.0 above methods</span></span><span style="color: #000000;"><span style="color: #000000;">uiusernotificationsettings</span></span>*settingnoti = [uiusernotificationsettings settingsfortypes:uiusernotificationtypebadge| uiusernotificationtypesound|<span style="color: #000000;"><span style="color: #000000;">Uiusernotificationtypealert categories:nil]; [[uiapplication sharedapplication] registerusernotificationsettings:settingnoti]; [application registerforremotenotifications];<br><br>iOS7.0 and the following methods</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Uiremotenotificationtype type = uiremotenotificationtypealert| uiremotenotificationtypebadge| uiremotenotificationtypesound;</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">[application registerforremotenotificationtypes:type]; </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">process has been closed (process is dead, come in again), get remote notification content</span></span>Uilocalnotification *location =<span style="color: #000000;"><span style="color: #000000;">launchoptions[uiapplicationlaunchoptionsremotenotificationkey]; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span><span style="color: #000000;"><span style="color: #000000;">(location) {NSLog (</span></span><span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">%@</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">, location.userinfo); }</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Else</span></span><span style="color: #000000;"><span style="color: #000000;">{NSLog (</span></span><span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">%@</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">, location.userinfo); } </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span><span style="color: #000000;"><span style="color: #000000;">YES;}</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">successful registration will call Appdelegate the following method, get the Device's devicetoken</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>) application: (uiapplication *) application didregisterforremotenotificationswithdevicetoken: (NSData *<span style="color: #000000;"><span style="color: #000000;">) Devicetoken{NSLog (</span></span><span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Get devicetoken:%@</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">, devicetoken); }</span></span><span style="color: #008000;"><span style="color: #008000;">/*</span></span><span style="color: #008000;"><span style="color: #008000;">when a device receives a remote push notification, if the program is turned off, the system launches the program to the background while the user is presented with a remote push notification, and calls the following method of Appdelegate</span></span><span style="color: #008000;"><span style="color: #008000;">*/</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>) application: (uiapplication *) application didreceiveremotenotification: (nsdictionary *) userInfo Fetchcompletionhandler: (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>(^<span style="color: #000000;"><span style="color: #000000;">) (uibackgroundfetchresult)) completionhandler{</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span><span style="color: #000000;"><span style="color: #000000;">(userInfo) {nsdictionary</span></span>*aps = userinfo[<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">APS</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">]; Uialertview</span></span>*alert = [[uialertview alloc] initwithtitle:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">a new message</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>Message: [nsstring stringwithformat:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">%@</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>, aps[<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Alert</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>]]<span style="color: #0000ff;"><span style="color: #0000ff;">Delegate</span></span>: Self Cancelbuttontitle:nil otherbuttontitles:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Cancel</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">, nil]; [alert show]; } }</span></span><span style="color: #008000;"><span style="color: #008000;">/*</span></span><span style="color: #008000;"><span style="color: #008000;">when the user clicks on the remote push notification, will automatically open the app, there are 2 cases 1th: the app is not closed, has been hidden in the background to let the app into the foreground, and will call Appdelegate the following method (not restart the app</span></span><span style="color: #008000;"><span style="color: #008000;">*/</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>) application: (uiapplication *) application didreceiveremotenotification: (uilocalnotification *<span style="color: #000000;"><span style="color: #000000;">) Notification{NSLog (</span></span><span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">remotenotification=%@</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">, notification);}</span></span><span style="color: #008000;"><span style="color: #008000;">/*</span></span><span style="color: #008000;">in <span style="color: #008000;">This method can do some data download operation, in order to the user click on the notification before the data download completed to call Completionhandler this block, to inform the download completed Completionhandler ( uibackgroundfetchresultnewdata);</span></span><span style="color: #008000;"><span style="color: #008000;">*/</span></span><span style="color: #800080;"><span style="color: #800080;">3</span></span><span style="color: #000000;"><span style="color: #000000;">. Download pushmebadydemo, test remote Notifications</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Note When using pushmebady, an unnecessary error is annotated in the IoSock.h file as shown in the following Face.</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">#include <coreservices/. /frameworks/carboncore.framework/headers/mactypes.h></span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Import a developer or publisher push certificate on your computer. modify the name to Apns.cer</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">here to fill in the obtained Devicetoken</span></span>Self.devicetoken =<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">e3094258 d8766f77 f29dfbfa ec3e3e83 8f0c213e 01e0eeea cc040536 e7d41730</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">; </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">here is the release of the remote notification content</span></span>Self.payload =<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">{\</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>Aps\<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">: {\ "alert\": \ "xing zi love kind girl. \" \ "badge\": 1}}</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">;</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">here is the remote notification APNs Publishing Certificate</span></span>Self.certificate = [[nsbundle mainbundle] pathforresource:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">APNs</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>OfType:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">cer</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>];</pre><p><p>Two. Aurora Push (jpush)</p></p><p><p>1. What is Aurora push (jpush)</p></p><pre><pre><span style="color: #800080;">1</span> <span style="color: #000000;">a set of remote push solutions that support Android and iOS two platforms</span> <span style="color: #800080;">2</span>. It can quickly add push function to iOS app, reduce the workload, development complexity of integration APNs</pre></pre><p><p>2. The steps are as Follows:</p></p><p><p>1. Register your account and create your app.</p></p><p><p>2. Fill in the application information, develop the certificate and the production Certificate password is the password that you exported the certificate to generate the P12 file.</p></p><p><p>3. Export the development and release (production) push certificate, then set the password</p></p><p><p></p></p><p><p>4.JPush automatically records and manages all devices that have installed this app devicetoken, and with jpush, you can easily send remote push notifications to all your Devices.</p></p><p><p></p></p><p><p>To be continued .......</p></p><p><p></p></p><p><p>iOS remote push</p></p></span>

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.