Feature implementation: A jumps to B and opens the specified page in b
Steps:
1. First create two projects (Project A, Project B), add the URL Types in the Info.plist file in Project B, as shown in: Where URL idenifier is the bundle ID of Project B, add a command prefix to the URL schemes, I use " PROJECTB ", this name can be taken, run the project B.
2. Add a jump code to project a
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"projectB://"]];
Here the URL of the command prefix must be consistent with the previous definition, I added this line of code to a button click Method, now click on the button can jump to project B.
3. Now say that the app jumps between the communication, in fact, the same as the value of the transfer. Click on the second button in project A to add code
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"projectB://openBSecondPage"]];
4. Project B adds a Nsurl attribute in Appdelegate that implements a proxy method that receives the URL passed from project A.
-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{ self.url = url; return YES;}
Then add the code to the first interface in B
- (void) Viewdidload {[Super Viewdidload];Nsurl * url = ((Appdelegate *) [ uiapplication Sharedapplication] .delegate) .URL; if (URL) {//shows the Url,url = Projectb://openbsecondpage obtained from a Host = Openbsecondpage self.label .text = [nsstring stringwithformat:@ "url =%@,host =%@", [url Absolutestring],[url host]; //some operations based on the host of the transmitted URLs if ([[URL host]isequaltostring:@< Span class= "hljs-string" > "Openbsecondpage"]) {//jump to the second interface [ "second" Sender:nil];}}}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
In short, some custom actions are made after opening project B from a URL passed from a.
The specific parsing process for B is: Nsurl * url = ((Appdelegate *) [uiapplication sharedapplication].delegate). URL;
;
if (URL) {
Nsarray *arr = [url.host componentsseparatedbystring:@ "&"];
NSLog (@ "%@", arr);
UILabel *lab = [[UILabel alloc]initwithframe:cgrectmake (10, 200, 300, 300)];
Lab.text = [NSString stringwithformat:@ "%@", arr];
Lab.numberoflines = 0;
[Self.view Addsubview:lab];
Take some action based on the host of the URL passed in
if ([Arr.lastobject isequaltostring:@ "Openurl=openbsecondpage"]) {
Jump to the second interface
Secondviewcontroller *sec = [[Secondviewcontroller alloc]init];
[Self.navigationcontroller pushviewcontroller:sec Animated:yes];
}
}
IOS One app jumps to another app and communicates (e.g. a jumps to B and opens the specified page in B)