IOS: Aurora Push Controller Jump

Source: Internet
Author: User

In front of the Aurora message has been pushed, then there is news, how to jump to the required controller? In fact, mainly in the UserInfo this message to do judgment to deal with, specifically as follows:

The following two are the way to receive messages when the remote push, this is the method provided by the application, as long as the successful registration of the Aurora push, push the message, the two methods will be called, in both methods received the USERINFO message to make a judgment.

Required,for systems with less than or equal to IOS6

-(void) Application: (UIApplication *) application didreceiveremotenotification: (Nsdictionary *) UserInfo;

IOS 7 Support Required

-(void) Application: (UIApplication *) application didreceiveremotenotification: (nsdictionary *) userInfo Fetchcompletionhandler: (void (^) (uibackgroundfetchresult)) Completionhandler;

The specific code is as follows: I'm here to distinguish the ring letter push message controller jump and ring-mail push message controller jump

set up custom fields on the server for Aurora push , the message controller that is used to determine the jump is the Aurora push

-(void) Application: (UIApplication *) application didreceiveremotenotification: (Nsdictionary *) userinfo{//Required,for systems with less than or equal to IOS6[Jpushservice handleremotenotification:userinfo];}-(void) Application: (UIApplication *) application didreceiveremotenotification: (nsdictionary *) userInfo Fetchcompletionhandler: (void(^) (Uibackgroundfetchresult)) completionhandler{//IOS 7 Support Required[Jpushservice Handleremotenotification:userinfo]; if(Completionhandler) {Completionhandler (uibackgroundfetchresultnewdata); }    //message Prompt numberSelf.badge = userinfo[@"CP1"][@"badge"]; //get extras field contentsNSString *customizevalue = [UserInfo valueforkey:@"Customizeextras"];//Server extras field, key is defined by itself, to determine the jump is the Aurora push message controller//start the program and jump to the Aurora push message controller    if([Customizevalue isequaltostring:@"Jpush"]) {Kjtabviewcontroller*ROOTVC = (Kjtabviewcontroller *) [UIApplication Sharedapplication].keywindow.rootviewcontroller; Rootvc.selectedindex=4; Kjnavgationcontroller*NAVC = rootvc.viewcontrollers[4]; SELF.MINEVC= navc.viewcontrollers[0]; Kjnewfriendcontroller*NEWVC =[[Kjnewfriendcontroller alloc]init];        [Self.mineVC.navigationController PUSHVIEWCONTROLLER:NEWVC Animated:yes];        [Self cancelbadgevalue]; Application.applicationiconbadgenumber-=[Self.badge IntegerValue]; }    Else{//start the program and jump to the controller of the ring letter push messageKjtabviewcontroller *ROOTVC = (Kjtabviewcontroller *) [UIApplication Sharedapplication].keywindow.rootviewcontroller; Rootvc.selectedindex=1; }            //The app is processing foreground status and will not receive aurora push messages, so there is a need for extra processing here    if(Application.applicationstate = =uiapplicationstateactive) {Uialertview*alert =[[Uialertview alloc] Initwithtitle:@"you have a push message"message:userinfo[@"APS"][@"Alert"]                              Delegate: Self cancelbuttontitle:@"Cancel"Otherbuttontitles:@"Determine", nil];                [Alert show]; //register for monitoring, cancel the badgevalue number[Notycenter addobserver:self selector: @selector (cancelbadgevalue) Name:@"cancelbadgevaluenotification" Object: nil]; }}#pragmamark-uialertviewdelegate-(void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (nsinteger) buttonindex{Uiviewcontroller*CURRENTVC =[self GETCURRENTVC]; if([CURRENTVC Iskindofclass:[kjtabviewcontrollerclass]]) {//Root ControllerKjtabviewcontroller *ROOTVC = (Kjtabviewcontroller *) CURRENTVC; Kjnavgationcontroller*NAVC = rootvc.viewcontrollers[4]; SELF.MINEVC= navc.viewcontrollers[0]; if(Buttonindex = =0) {Self.mineVC.tabBarItem.badgeValue= [NSString stringWithFormat:@"%@", Self.badge]; }Else{Kjnewfriendcontroller*NEWVC =[[Kjnewfriendcontroller alloc]init]; Rootvc.selectedindex=4;            [Self.mineVC.navigationController PUSHVIEWCONTROLLER:NEWVC Animated:yes];        [Self cancelbadgevalue]; }    }Else{//non-root controllerKjtabviewcontroller *ROOTVC = (Kjtabviewcontroller *) [UIApplication Sharedapplication].keywindow.rootviewcontroller; Kjnavgationcontroller*NAVC = rootvc.viewcontrollers[4]; SELF.MINEVC= navc.viewcontrollers[0]; if(Buttonindex = =0) {Self.mineVC.tabBarItem.badgeValue= [NSString stringWithFormat:@"%@", Self.badge]; }        if(Buttonindex = =1) {[Currentvc.navigationcontroller poptorootviewcontrolleranimated:no]; Rootvc.selectedindex=4; Kjnewfriendcontroller*NEWVC =[[Kjnewfriendcontroller alloc]init];            [Self.mineVC.navigationController PUSHVIEWCONTROLLER:NEWVC Animated:yes];        [Self cancelbadgevalue]; }    }}#pragmaMark-number of Aurora messages canceled-(void) cancelbadgevalue{Self.mineVC.tabBarItem.badgeValue=Nil;}/** * Get viewcontroller of current screen display*/-(Uiviewcontroller *) getcurrentvc{Uiviewcontroller*result =Nil; UIWindow* Window =[[UIApplication sharedapplication] Keywindow]; if(Window.windowlevel! =uiwindowlevelnormal) {Nsarray*windows =[[UIApplication sharedapplication] windows];  for(UIWindow * Tmpwininchwindows) {            if(Tmpwin.windowlevel = =uiwindowlevelnormal) {window=Tmpwin;  Break; } }} UIView*frontview = [[Window subviews] Objectatindex:0]; IDNextresponder =[Frontview Nextresponder]; if([Nextresponder Iskindofclass:[uiviewcontrollerclass]]) {result=Nextresponder; }Else{result=Window.rootviewcontroller; }    returnresult;}

IOS: Aurora Push Controller Jump

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.