IOS jumps from one app to another and jumps to the specified page with parameters

Source: Internet
Author: User





Feature implementation: A jumps to B and opens the specified page in b



Steps:



1. First create two projects (Project A, Project B), add a URL Types to the Info.plist file in Project B, as shown in the following illustration: Where the URL idenifier is the bundle ID of Project B, and the URL schemes adds a command prefix that I use here. ProjectB ", the name can be taken by itself, run the project B.



2. Add jump code in Project a


[[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "projectb://"];


The command prefix for the URL must be the same as it was previously defined, and I added this line of code to a button click Method, and now click the button to jump to item B.



3. Now next to the app jump communication, in fact, with the value of almost. The click Method for the second button in item a adds code


[[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@ "Projectb://openbsecondpage"];


4. Add a Nsurl attribute to appdelegate in Project B to implement an agent method to receive URLs from project a


-(BOOL) Application: (UIApplication *) application Handleopenurl: (nsurl *) URL
{
    self.url = URL;
    Return YES
}


Then add code to the first interface in B


-(void) viewdidload {
    [super viewdidload];
    Nsurl * url = ((Appdelegate *) [uiapplication sharedapplication].delegate). url;
    if (URL) {
        //show Url,url = Projectb://openbsecondpage,host = openbsecondpage
        self.label.text = [NSString stringwithformat:@ "url =%@,host =%@", [url Absolutestring],[url host]];
        Perform some actions according to the host of the URL that is passed in
        ([[url host]isequaltostring:@ "Openbsecondpage"]) {
            //jump to the second interface
            [self performseguewithidentifier:@ "Second" Sender:nil];}}




In short, you do some custom actions based on the URL that comes from a that opens project B


Related Article

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.