The iOS user clicks the push message into the app and automatically jumps to the corresponding Viewcontroller

Source: Internet
Author: User

When an iOS user enters the app by clicking the push message, the Appdelegate

-(BOOL) Application: (uiapplication*) Application didfinishlaunchingwithoptions: (nsdictionary*) launchOptions

We can pass

NSDictionary* remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

Get the push userinfo.
But Didfinishlaunchingwithoptions will be more than Mainviewcontroller viewdidload first execution, at this time certainly cannot present a new view, You should let Mainviewcontroller start and check if you received the push, and then open the corresponding view
If Remotenotification is not empty, then the user enters by pushing the message, then a property can be declared

@property (nonatomic) BOOL islaunchedbynotification;

Used to identify whether the user entered the app by clicking the notification message.
At this time

-(void) Application: (uiapplication*) Application didreceiveremotenotification: (nsdictionary*) UserInfo

Must be called, iOS7 can be used

-(void) Application: (uiapplication*) Application didreceiveremotenotification: (nsdictionary*) UserInfo Fetchcompletionhandler: (void (^) (uibackgroundfetchresult)) Completionhandler

Since this method is called, Mainviewcontroller has already been initialized, so we can register a push message listener in Mainviewcontroller to show the corresponding view, as follows:

// Subscribe to the Presentation view message and open a branch view directly [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (presentview:) Name:@ "  Presentview"object: nil"; // a pop-up message box prompts the user for a subscription notification message. Primarily for users when using the app, pop-up prompts [[Nsnotificationcenter defaultcenter] addobserver:self selector: @selector (shownotification :) Name:@ "Notification"object: nil];

Therefore, in the Appdelegate didreceiveremotenotification can be judged by the islaunchedbynotification to inform different presentation methods.




The iOS user clicks the push message into the app and automatically jumps to the corresponding Viewcontroller

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.