I have an app lets say 2 apps - app1,app2 Lets say I open from app1 app2. How can I send data back from app2 with custom url schemes,like in facebook app? If I reopen app1 with url,I will see go back to app2,and its not good idea for my case. I want to open app2 like presented modally,and dismiss it with returned data.Is it possible?
Asked
Active
Viewed 212 times
1 Answers
1
You can define custom URL Schema for your app from info.plist file. you can check existing Thread on SO for this.
In your case,for example In app1- define custom url myAppOneScheme
and in your app2, Define custom url myAppTwoScheme
.
When you open app2 from app 1, Pass app1's url like this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"myAppOneScheme://test?callerURL= myAppOneScheme"]];
from app2, handle openURL method:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSLog(@"url recieved: %@", url);
NSLog(@"query string: %@", [url query]);
NSLog(@"host: %@", [url host]);
NSLog(@"url path: %@", [url path]);
NSDictionary *dict = [self parseQueryString:[url query]];
NSLog(@"query dict: %@", dict);
// NSString callerurl = parse callerURL from query
// store callerurl in user default or global variable.
return YES;
}
when you are done with operations in app2 and want to go back to app1, open caller url
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:"%@//testback?response=%@", caller url , datayouwanttoSendback]]];
Now, in your app1, again handle open url method and parse response

Community
- 1
- 1

PlusInfosys
- 3,416
- 1
- 19
- 33
-
Ok,in this case I will see go back to app1,after [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:"%@//testback?response=%@", caller url , datayouwanttoSendback] from ios system api,like back to safari.am I right? – Narek Simonyan Nov 30 '16 at 14:28
-
I want it to be like facebook open modally from bottom to top and close it like dismiss controller – Narek Simonyan Nov 30 '16 at 14:30