iOS Aurora push Click Push Message Jump Page

Source: Internet
Author: User
<span id="Label3"></p><pre class="hljs objectivec"><code class="objectivec">- (<span class="hljs-built_in">BOOL) Application: (<span class="hljs-built_in">UIApplication *) Application Didfinishlaunchingwithoptions: (<span class="hljs-built_in">Nsdictionary *) Launchoptions {<span class="hljs-preprocessor">#if __iphone_os_version_max_allowed > __iphone_7_1<span class="hljs-keyword">If ([[<span class="hljs-built_in">Uidevice currentdevice]<span class="hljs-variable">. systemversion floatvalue] >=<span class="hljs-number">8.0) {[apservice Registerforremotenotificationtypes: (<span class="hljs-built_in">Uiusernotificationtypebadge |<span class="hljs-built_in">Uiusernotificationtypesound |<span class="hljs-built_in">Uiusernotificationtypealert) categories:<span class="hljs-literal">nil]; }<span class="hljs-keyword">else {[apservice Registerforremotenotificationtypes: (<span class="hljs-built_in">Uiremotenotificationtypebadge |<span class="hljs-built_in">Uiremotenotificationtypesound |<span class="hljs-built_in">Uiremotenotificationtypealert)<span class="hljs-preprocessor">#else categories:<span class="hljs-literal"><span class="hljs-literal">nil]; [apservice registerforremotenotificationtypes: (<span class="hljs-built_in">uiremotenotificationtypebadge | <span class="hljs-built_in">uiremotenotificationtypesound | <span class="hljs-built_in">uiremotenotificationtypealert) <span class="hljs-preprocessor"> #endif categories:<span class="hljs-literal">nil];} [apservice setupwithoption:launchoptions]; <span class="hljs-keyword">if (launchoptions) {<span class="hljs-built_in">nsdictionary * remoteNotification = [ Launchoptions Objectforkey:<span class="hljs-built_in">uiapplicationlaunchoptionsremotenotificationkey];<span class="hljs-comment">//this judgment is to be notified when the program is not running, click on the notification jump page <span class="hljs-keyword">if (remotenotification) {<span class="hljs-built_in">nslog (<span class="hljs-string">@ "push message = =%@", remotenotification); [<span class="hljs-keyword">self gotomssageviewcontrollerwith:remotenotification];} }}</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre><pre class="hljs objectivec"><pre class="hljs objectivec"><code class="objectivec">- (<span class="hljs-keyword">void)application:(<span class="hljs-built_in">UIApplication *)application didRegisterUserNotificationSettings:(<span class="hljs-built_in">UIUserNotificationSettings *)notificationSettings{ [application registerForRemoteNotifications];}</span></span></span></code></pre></pre><pre class="hljs objectivec"><pre class="hljs objectivec"><code class="objectivec">- (<span class="hljs-keyword">void)application:(<span class="hljs-built_in">UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(<span class="hljs-built_in">NSData *)deviceToken{ [APService registerDeviceToken:deviceToken]; <span class="hljs-built_in">NSLog(<span class="hljs-string">@"%@", [<span class="hljs-built_in">NSString stringWithFormat:<span class="hljs-string">@"Device Token: %@", deviceToken]);}</span></span></span></span></span></span></span></code></pre></pre><p><p>The system will callback this method when Devicetoken gets a failure</p></p><pre class="hljs objectivec"><pre class="hljs objectivec"><code class="objectivec">- (<span class="hljs-keyword">void)application:(<span class="hljs-built_in">UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(<span class="hljs-built_in">NSError *)error{ <span class="hljs-built_in">NSLog(<span class="hljs-string">@"DeviceToken 获取失败,原因:%@",error);}</span></span></span></span></span></code></pre></pre> <ul> <ul> <li>The following method is also important, here is the main processing of the message pushed over</li> </ul> </ul><pre class="hljs objectivec"><code class="objectivec">- (<span class="hljs-keyword">Void) Application: (<span class="hljs-built_in">UIApplication *) Application Didreceiveremotenotification: (<span class="hljs-built_in">Nsdictionary *) userinfo{<span class="hljs-built_in">NSLog (<span class="hljs-string">@ "===%@ Push message", userInfo);<span class="hljs-comment"><span class="hljs-comment">//get APNs Standard Information content, if not necessary can not take <span class="hljs-built_in">nsdictionary *aps = [userInfo Valueforkey:<span class="hljs-string">@ "aps"]; <span class="hljs-built_in">nsstring *content = [aps valueforkey:<span class="hljs-string">@ "alert"]; <span class=" Hljs-comment ">//push Display content <span class=" hljs-built_in ">nsinteger badge = [[aps Valueforkey:<span class=" hljs-string ">@ "badge"] integervalue]; <span class="hljs-built_in">nsstring *sound = [aps valueforkey:<span class="hljs-string">@ "sound"]; <span class=" Hljs-comment ">//play Sound <span class=" hljs-comment ">//get custom field content, UserInfo is the JSON data returned in the background, is a dictionary [apservice handleremotenotification:userinfo]; Application<span class="hljs-variable">.applicationiconbadgenumber = <span class="hljs-number">0; [<span class="hljs-keyword">self gotomssageviewcontrollerwith:userinfo];} </span> </span> </span> </span> </span> </span> </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre><pre class="hljs objectivec"><pre class="hljs objectivec"><code class="objectivec">- (<span class="hljs-keyword">void)applicationWillEnterForeground:(<span class="hljs-built_in">UIApplication *)application { [application setApplicationIconBadgeNumber:<span class="hljs-number">0]; <span class="hljs-comment">//清除角标 [application cancelAllLocalNotifications];}</span></span></span></span></code></pre></pre><pre class="hljs objectivec"><code class="objectivec">- (<span class="hljs-keyword">Void) Gotomssageviewcontrollerwith: (<span class="hljs-built_in">Nsdictionary*) msgdic{<span class="hljs-comment">Save the field to local, because you want to jump to the page with it to judge, here I only introduce jump to a page,<span class="hljs-built_in">Nsuserdefaults*pushjudge = [<span class="hljs-built_in"><span class="hljs-built_in">nsuserdefaults standarduserdefaults]; [pushjudge setobject:<span class="hljs-string">@ "push" forkey:<span class="hljs-string">@ "push"]; [pushjudge synchronize]; <span class="hljs-built_in">nsstring * targetstr = [msgdic objectforkey:<span class="hljs-string">@ "target"]; <span class="hljs-keyword">if ([targetstr isequaltostring:<span class="hljs-string">@ "notice"]) {MESSAGEVC * VC = [[ MESSAGEVC alloc]init]; <span class="hljs-built_in">uinavigationcontroller * Nav = [<span class="hljs-built_in">uinavigationcontroller alloc]initwithrootviewcontroller:vc]; <span class="hljs-comment">//here plus navigation bar is because I jump to the page with the navigation bar, if the jump page without navigation, then this sentence please Save. [<span class="hljs-keyword">self<span class="hljs-variable">.window<span class="hljs-literal" . rootviewcontroller presentviewcontroller:nav animated:<span>YES completion:<span class=" Hljs-literal ">nil"; }}</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre> <ul> <ul> <li>The following describes the page to jump MESSAGEVC inside what to do, in fact, the code is very simple. Look at the code, create a return button in viewwillappear, according to the field in the Appdelegate with Nsuserdefaults saved to Judge.</li> </ul> </ul><pre class="hljs objectivec"><code class="objectivec">-(<span class="hljs-keyword">Void) Viewwillappear: (<span class="hljs-built_in">BOOL) animated{[<span class="hljs-keyword">Self<span class="hljs-variable">. Navigationcontroller Setnavigationbarhidden:<span class="hljs-literal">NO animated:<span class="hljs-literal">YES]; [<span class="hljs-keyword">Super Viewwillappear:<span class="hljs-literal">YES];<span class="hljs-built_in">Nsuserdefaults*pushjudge = [<span class="hljs-built_in"><span class="hljs-built_in">nsuserdefaults standarduserdefaults]; <span class="hljs-keyword">if ([[pushjudge objectforkey:<span class="hljs-string">@ "push"]isequaltostring:<span class="hljs-string">@ "push"] {<span class="hljs-keyword">self<span class="hljs-variable">.navigationitem<span class="hljs-variable">.leftbarbuttonitem = [[<span class="hljs-built_in">uibarbuttonitem alloc]initWithImage:[< Span class= "hljs-built_in" >uiimage imagenamed:<span class="hljs-string">@ "[email protected]"] Style:<span class="hljs-built_in">uibarbuttonitemstyleplain target:<span class="hljs-keyword">self action: <span class="hljs-keyword"> @selector (rebacktorootviewaction)]; }<span class="hljs-keyword">else{<span class="hljs-keyword">self<span class="hljs-variable">.navigationItem< Span class= "hljs-variable" >.leftbarbuttonitem=<span class="hljs-literal">nil;}} </span> </span> </span> </span> </span> </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre><pre class="hljs objectivec"><pre class="hljs objectivec"><code class="objectivec">- (<span class="hljs-keyword">void)rebackToRootViewAction { <span class="hljs-built_in">NSUserDefaults * pushJudge = [<span class="hljs-built_in">NSUserDefaults standardUserDefaults]; [pushJudge setObject:<span class="hljs-string">@""forKey:<span class="hljs-string">@"push"]; [pushJudge synchronize];<span class="hljs-comment">//记得立即同步 [<span class="hljs-keyword">self dismissViewControllerAnimated:<span class="hljs-literal">YES completion:<span class="hljs-literal">nil];}</span></span></span></span></span></span></span></span></span></code></pre></pre><p><p><em>so It's Done. </em>The following post is posted back in the background fields, I was based on these lots to determine the different pages Jump.</p></p> <br>Screen shot 2015-11-24 pm 8.50.02.png<p><p><br>is a background to the interface document</p></p><br>Screen shot 2015-11-24 pm 9.35.55.png<p><p><br>The above code may be a bit messy, please leave a message if in doubt<br>Look too code too messy under the</p></p><br>Screen shot 2015-11-24 pm 9.39.05.png<br>Screen shot 2015-11-24 pm 9.40.08.png<br>Screen shot 2015-11-24 pm 8.58.11.png<br>Screen shot 2015-11-24 pm 9.40.43.png<p><p>The code in the above 5 figures is inside the APPDELEGATE.M.</p></p><p><p>The following figure is inside the messagevc, which is the page you want to jump to.</p></p><br>Screen shot 2015-11-24 pm 9.42.27.png<p><p><br><br></p></p><p><p>iOS Aurora push Click Push Message Jump Page</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.