IOS about homing pigeon Push-click push notification processing

Source: Internet
Author: User
<span id="Label3"></p><p><p>Recent projects using the push module, the use of the Penguin Empire <strong>carrier pigeon push service</strong> , about the specific how to push the certificate, how to set up, I will not repeat, as the development of the document has been said very clearly, and secondly in the online search words can also search a lot; <strong> Here is the main write about the push notification came after the click on this notice how to deal with,</strong> but also to do a note after you finish</p></p><p><p>Here in my project to achieve the effect is to click on the <em><strong>notification bar push message, the corresponding page into the application</strong></em> , the default effect is to click the push message, will go directly to the app, <em><strong>if the app does not start, will launch the app into the first page</strong></em> <em><strong>, if the app has started, Just click Home back into the background, it will return to the application, and the application before the interface, which is still the interface;</strong></em></p></p><p><p>1. <strong>If the app does not start</strong></p></p><p><p>You can use the</p></p> <blockquote> <blockquote> <p>-(BOOL) application: (uiapplication*) application didfinishlaunchingwithoptions: (nsdictionary*) launchOptions</p> </blockquote> </blockquote><p><p>method to determine whether to click on the icon to launch the app or click the push message to launch the app, <strong>if it is clicked push launch application, the above method of the launchoptions will not be nil, can be judged by nil;</strong></p></p> <blockquote> <blockquote> <p>if (<strong>launchoptions</strong>) {</p> <p>nsdictionary* <strong>remotenotification</strong> = [launchoptionsobjectforkey: uiapplicationlaunchoptionsremotenotificationkey];</p> <p>If (remotenotification) {</p> <p>NSLog (@ "push over the message is%@", remotenotification);</p> <p>Click Push notification to enter the specified interface (this is definitely the equivalent of entering from the Background)</p> <p>[self <strong>gotomssageviewcontrollerwith:</strong>remotenotification];//how to enter the corresponding page</p> <p>}</p> <p>}</p> </blockquote> </blockquote><p><p>The returned dictionary <strong>remotenotification</strong> is the <strong>push message body</strong> , where you can print to view and then determine if <strong>you clicked the push message to launch the app, Gotomssageviewcontrollerwith:</strong> The method inside the code to enter their own message corresponding to the page (again)</p></p><p><p>2. <strong>If the app is started, hang it in the background</strong></p></p><p><p>In this case, clicking the push message into the app will call</p></p> <blockquote> <blockquote> <p>-(void) application: (uiapplication*) application didreceiveremotenotification: (nsdictionary*) userInfo</p> </blockquote> </blockquote><p><p><strong>UserInfo is the subject of the message being Pushed.</strong></p></p><p><p>In this method, you can make your own code operation to enter the message corresponding page</p></p><p><p>3. <strong>If the app is running in the foreground when the push message arrives</strong></p></p><p><p>This situation still calls 2. The method, but if you do not set anything, the user will not know that you pushed the message, if you set up the corresponding page, the application will suddenly come into the corresponding interface, the experience is not good; this time you need to determine whether the application is running in the foreground or in the background (if the program does not start to consider this</p></p> <blockquote> <blockquote> <p>if (<strong>[uiapplicationsharedapplication].applicationstate</strong>==uiapplicationstateactive)</p> <p>{//when The foreground is running, you receive a push notification that pops up a alertview reminder</p> <p>Nsdictionary*onedict = [userinfoobjectforkey:@ "aps"];</p> <p>Nsdictionary*twodict = [onedictobjectforkey:@ "alert"];</p> <p>nsstring*msg = [twodictobjectforkey:@ "body"];</p> <p>Uialertview*alert = [uialertviewalloc]initwithtitle:@ "warm tip" message:msgdelegate:selfcancelButtonTitle: nilotherbuttontitles:@ "ok", nil];</p> <p>[alertshow];</p> <p>}</p> <p>else if ([uiapplicationsharedapplication].applicationstate==uiapplicationstateinactive)</p> <p>{//click on push notification to enter the interface</p> <p>[self gotomssageviewcontrollerwith:userinfo];</p> <p>}</p> </blockquote> </blockquote><p><p><strong>uiapplicationsharedapplication].applicationstate</strong> has three states, the uiapplicationstateactive//application is running in the foreground</p></p><p><p>Uiapplicationstateinactive//click on push notifications to enter the app</p></p><p><p>Uiapplicationstatebackground//app hangs in background</p></p><p><p>It is only necessary to determine whether the application is running in the <strong>foreground (2.)</strong> or <strong>click on Push notification to enter the application (3.)</strong> , and then the corresponding processing, I am using the project is if the foreground is running, push the message to the pop-up window, but the feeling is not very good, Readers can use their own methods, or the third party Mbprogresshud in the emergence of the two or three-second automatic disappearance of the control to operate, if you click on the push notification to enter the application, I still use the method to enter the corresponding interface</p></p><p><p><strong>4. How to access the push message corresponding interface</strong></p></p><p><p>Play came to the amount, do this piece of time I searched on the internet a lot, but there is not much worth reference to the information, the last words in the Cocoachina forum to find a worthy reference http://www.cocoachina.com/bbs/read.php?tid= 257582, the inside of the 8 floor said very reasonable, I also based on this;</p></p><p><p>First of all about the <strong>push message</strong> This piece, such as you push the message into three categories, one is click the message into a page, one is click into the B page, one is click into the C page, you can set an event value EventID in the message body of the push, Definition 101 is about a page of the message, 102 is about the B page of the message, 103 is about the C page of the message, and then received the message body parsed out to judge, you can use the switch case to judge,</p></p> <blockquote> <blockquote> <p>Nsintegereventid = [[msgdic objectforkey:@ "eventId"]integervalue];</p> <p>Switch (EventID) {</p> <p>Case101: {//write The code into page a</p> <p>Break</p> <p>}</p> <p>Case102: {//write the code into page b</p> <p>Break</p> <p>}</p> <p>Case103: {//write the code into the C page</p> <p>Break</p> <p>}</p> <p>Default</p> <p>Break</p> <p>}</p> </blockquote> </blockquote><p><p>Then is to enter the corresponding interface, I do the processing is a known <strong>message after the interface</strong> , in the Appdelegate file contains the interface header file, and then initialize at the corresponding location, and then present the past</p></p> <blockquote> <blockquote> <p>case101: {</p> <p>Enter a interface</p> <p>Aviewcontroller *AVC = [[aviewcontroller alloc] init];</p> <p>[self.window.rootViewController <strong>presentviewcontroller:a</strong>vc <strong>animated:</strong>YES <strong>completion: </strong>nil] ;</p> <p>Break</p> <p>}</p> </blockquote> </blockquote><p><p>Here are a few things to Explain.</p></p><p><p>The first, the above code is just for a simple page with no navigation bar, and a page and its upper interface does not have data transfer, that is, the initialization of a page does not use the data on the first page of it</p></p><p><p>second, It is obvious that the page you want to enter is not as simple as a; as I do this time, there is a category that goes into a <strong>page with a navigation bar</strong> ; One of the <strong>tabs that goes into Tabbar</strong></p></p><p><p><strong>A. How to access a page with a navigation bar</strong></p></p><p><p>I have only been looking for this problem for a long time, tempted several ways, such as using the root view of the navigation controller to push, are not, and finally used to refer to the forum before the method;</p></p> <blockquote> <blockquote> <p>case101: {</p> <p>Go to a page with navigation bar</p> <p>AVIEWCONTROLLER*AVC = [[aviewcontrolleralloc]init];</p> <p><strong>Uinavigationcontroller*plannav = [[uinavigationcontrolleralloc]initwithrootviewcontroller:avc];</strong></p> <p>[self.window.rootViewController Presentviewcontroller:plannav Animated:yes completion:nil];</p> <p>Break</p> <p>}</p> </blockquote> </blockquote><p><p> Using the a page into the navigation controller, and then present navigation controller, so that click on the push message can be entered with the navigation controller page, <strong> If the A page is pushed from the previous interface, and the initialization of the use of the upper interface of some data </strong>, in this case, you need to let the push message to push the data together, and then parse, <strong> in the initialization of the above using this data to initialize, </strong> equivalent to sever its relationship with the upper interface; <strong> the rest </strong> Another point is <strong> the return key on the navigation bar </strong>, because it is present past, so the system navigation bar comes with the <strong> Backbarbuttonitem </strong> does not appear, Not even if you set it in the last block parameter of the present method; Here's what you said before that forum Buddy said the method, in the Viewwillappear method inside the judgment </p></p> <blockquote> <blockquote> <p>-(void) viewwillappear: (BOOL) animated {</p> <p>//to determine if a click is pushed over, and if so, set the left navigation tab as the return key </p> <p> Nsuserdefaults*pushjudge = [nsuserdefaultsstandarduserdefaults]; </p> <p> If ([[pushjudgeobjectforkey:@ "push"]isequaltostring:@ "]) {</p> <p>//add A Back button to the navigation bar to return the pushed page If it is not pushed into the page, it must be entered through the navigation bar, the page navigation bar will definitely have the navigation bar comes with the Leftbarbuttonitem back to the previous page </p> <p> Uibarbuttonitem*leftbutton = [[ Uibarbuttonitem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReplytarget:self action: @selector ( rebacktorootviewaction)]; </p> <p> Self.navigationitem.leftbarbuttonitem= leftbutton; </p> <p>}else{</p> <p> self.navigationitem.leftbarbuttonitem=nil; </p> <p>} </p> <p>} </p> </blockquote> </blockquote> <blockquote> <blockquote> <p>-(void) Rebacktorootviewaction {</p> <p>Empty the marked condition to prevent the page from being returned when the navigation bar is normally entered.</p> <p>Nsuserdefaults*pushjudge = [nsuserdefaults standarduserdefaults];</p> <p>[pushjudge setobject:@ "" forkey:@ "push"];</p> <p>[pushjudge synchronize];</p> <p>[self Dismissviewcontrolleranimated:yes completion:nil];</p> <p>}</p> </blockquote> </blockquote><p><p>is stored in the local storage nsuserdefaults to determine <strong>whether the click Push to enter the page,</strong> the judgment value is in the <strong>gotomssageviewcontrollerwith: (the above)</strong> method of deposit, Set this value before entering the corresponding page,</p></p> <blockquote> <blockquote> <p>-(void) gotomssageviewcontrollerwith: (nsdictionary*) Msgdic</p> <p>{</p> <p>Save fields locally</p> <p><strong>Nsuserdefaults*pushjudge = [nsuserdefaults standarduserdefaults];</strong></p> <p><strong>[pushjudge setobject:@ "push" forkey:@ "push"];</strong></p> <p><strong>[pushjudge synchronize];</strong></p> <p>Nsintegereventid = [[msgdic objectforkey:@ "eventId"] integervalue];</p> <p>Switch (EventID) {</p> <p>...</p> <p>}</p> <p>}</p> </blockquote> </blockquote><p><p>This will be the same as the corresponding page, click Back to return the previous application back to the background when the page</p></p><p><p><strong>B. How to enter one of the Tabbar tab pages</strong></p></p><p><p>This is actually very simple, because this certainly will not be related to the superior page, I use the method is to re-put all the label page into a tabbar, and then present the past is good;</p></p> <blockquote> <blockquote> <p>Roottabbarcontroller*tabbarcontroller = [roottabbarcontroller new];</p> <p>Uinavigationcontroller*aacontroller = [[uinavigationcontroller alloc] Initwithrootviewcontroller:[aaviewcontroller new]];</p> <p>Uinavigationcontroller*bbcontroller = [[uinavigationcontroller alloc] Initwithrootviewcontroller:[bbviewcontroller new]];</p> <p>Uinavigationcontroller*cccontroller = [[uinavigationcontroller alloc] Initwithrootviewcontroller:[ccviewcontroller new]];</p> <p>Nsarray*array_controllers = [nsarray arraywithobjects:aacontroller,bbcontroller,cccontroller,nil];</p> <p>tabbarcontroller.viewcontrollers= array_controllers;</p> <p>Tabbarcontroller.selectedviewcontroller= [tabbarcontroller.viewcontrollersobjectatindex:2];</p> <p>[tabbarcontrollersetselbtn:2];</p> <p>[self.window.rootViewControllerpresentViewController:tabBarControlleranimated:YEScompletion:nil];</p> </blockquote> </blockquote><p><p>These are simple methods;</p></p><p><p></p></p><p><p>from: Jane book,<span class="label"> Almond</span> ,</p></p><p><p>Links: HTTP://WWW.JIANSHU.COM/P/8B70E4124FC9</p></p><p><p>IOS about homing pigeon Push-click push notification processing</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.