iOS Aurora push Click Push Message Jump Page

Source: Internet
Author: User

Recently in the Aurora push, before the use of Baidu push, but the bad news delay, change the aurora, change it, doesn't matter anyway I won't, so began to see the Aurora push documents, in the heart scold with Baidu document detail degree can not compare ah, document very short a moment to read, in fact, the main code of the document these push platform are the same, Speaking of which I would like to vomit trough, originally thought push is very easy, the actual is easy, but was backstage and the Android developer to get me confused, a burst of anger! Just started back in the background is a push message is a JSON data, in fact, the correct should return the JSON data, but the background pushed to my notification message, his sister is directly able to see the contents of the data structure, what {aps: "sb123"} This type of, let me have no words indescribable feelings at the time, Later, he followed the requirements of the Android developer, replaced the notification message with a custom message, the notification and custom messages are completely different, the notification message is not changed, and the custom message is not the same, completely by the developer to do, the notification can be received at any time, but the custom message is not so casual, Custom message only when the program runs in the foreground will receive prompt, so I am not happy with the mood to let the background to see the iOS push documents, let him think about it, and then fortunately he read the document finally on the road, got it, good no nonsense, on the code!
The code cannot be missing:

- (BOOL) Application: (uiapplication*) Application Didfinishlaunchingwithoptions: (nsdictionary*) Launchoptions {#if __iphone_os_version_max_allowed > __iphone_7_1    if([[UideviceCurrentdevice]. SystemversionFloatvalue] >=8.0) {[Apservice registerforremotenotificationtypes: (Uiusernotificationtypebadge|Uiusernotificationtypesound|Uiusernotificationtypealert) Categories:Nil]; }Else{[Apservice registerforremotenotificationtypes: (Uiremotenotificationtypebadge|Uiremotenotificationtypesound|Uiremotenotificationtypealert)#elseCategoriesNil]; [Apservice registerforremotenotificationtypes: (Uiremotenotificationtypebadge|Uiremotenotificationtypesound|Uiremotenotificationtypealert)#endifCategoriesNil]; } [Apservice setupwithoption:launchoptions];if(launchoptions) {nsdictionary* Remotenotification = [launchoptions objectforkey:Uiapplicationlaunchoptionsremotenotificationkey];//The decision is to receive notification when the program is not running, click on the notification jump page        if(remotenotification) {NSLog(@ "push message = =%@", remotenotification); [ SelfGotomssageviewcontrollerwith:remotenotification]; }    }}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings{    [application registerForRemoteNotifications];}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{    [APService registerDeviceToken:deviceToken];    NSLog(@"%@", [NSString stringWithFormat:@"Device Token: %@", deviceToken]);}

The system will callback this method when Devicetoken gets a failure

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{    NSLog(@"DeviceToken 获取失败,原因:%@",error);}
    • The following method is also important, here is the main processing of the message pushed over
- (void) Application: (uiapplication*) Application Didreceiveremotenotification: (nsdictionary*) userinfo{NSLog(@ "A ===%@ push message", UserInfo);//Get APNs Standard Information content, if no need can not take    nsdictionary*aps = [UserInfo valueforkey:@ "APS"];NSString*content = [APs Valueforkey:@ "Alert"];//push to display content    Nsintegerbadge = [[APS Valueforkey:@ "badge"] IntegerValue];NSString*sound = [APs Valueforkey:@ "Sound"];//Play the Sound    //Get the custom field content, UserInfo is the JSON data returned in the background, is a dictionary[Apservice Handleremotenotification:userinfo]; Application. Applicationiconbadgenumber=0; [ SelfGotomssageviewcontrollerwith:userinfo]; }
- (void)applicationWillEnterForeground:(UIApplication *)application {    [application setApplicationIconBadgeNumber:0];   //清除角标    [application cancelAllLocalNotifications];}
- (void) Gotomssageviewcontrollerwith: (nsdictionary*) msgdic{//Put the field in local, because you want to jump to the page with it to judge, here I only introduce jump to a page,    Nsuserdefaults*pushjudge = [NsuserdefaultsStandarduserdefaults]; [Pushjudge SetObject:@ "Push"Forkey:@ "Push"]; [Pushjudge Synchronize];NSString* Targetstr = [Msgdic objectforkey:@ "Target"];if([Targetstr isequaltostring:@ "notice"]) {MESSAGEVC * VC = [[Messagevc alloc]init];Uinavigationcontroller* Nav = [[UinavigationcontrollerALLOC]INITWITHROOTVIEWCONTROLLER:VC];//The navigation bar here is because I jump to the page with the navigation bar, if the jump page without navigation, then this sentence please save. [ Self. Window. RootviewcontrollerPresentviewcontroller:nav Animated:YESCompletion:Nil]; }}
    • 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.
-(void) Viewwillappear: (BOOL) animated{[ Self. NavigationcontrollerSetnavigationbarhidden:NOAnimated:YES]; [SuperViewwillappear:YES];Nsuserdefaults*pushjudge = [NsuserdefaultsStandarduserdefaults];if([[Pushjudge Objectforkey:@ "Push"]isequaltostring:@ "Push"]) { Self. Navigationitem. Leftbarbuttonitem= [[Uibarbuttonitemalloc]initwithimage:[UIImageImagenamed:@ "[email protected]"] Style:UibarbuttonitemstyleplainTarget SelfAction@selector(Rebacktorootviewaction)]; }Else{ Self. Navigationitem. Leftbarbuttonitem=Nil; }}
- (void)rebackToRootViewAction {    NSUserDefaults * pushJudge = [NSUserDefaults standardUserDefaults];    [pushJudge setObject:@""forKey:@"push"];    [pushJudge synchronize];//记得立即同步    [self dismissViewControllerAnimated:YES completion:nil];}

so it's done. The following post is posted back in the background fields, I was based on these lots to determine the different pages jump.


Screen shot 2015-11-24 pm 8.50.02.png


is a background to the interface document


Screen shot 2015-11-24 pm 9.35.55.png


The above code may be a bit messy, please leave a message if in doubt
Look too code too messy under the


Screen shot 2015-11-24 pm 9.39.05.png
Screen shot 2015-11-24 pm 9.40.08.png
Screen shot 2015-11-24 pm 8.58.11.png
Screen shot 2015-11-24 pm 9.40.43.png

The code in the above 5 figures is inside the APPDELEGATE.M.

The following figure is inside the MESSAGEVC, which is the page you want to jump to.


Screen shot 2015-11-24 pm 9.42.27.png

In fact, this is very nice, it is written on the sometimes bug, you can try



The text/I called CC What's the matter (Jane book author)
Original link: http://www.jianshu.com/p/eaf07c4372a8
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".

iOS Aurora push Click Push Message Jump Page

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.