Swift - AppToApp communication
communicate with using URL
---------
create url schemes
go to prokject-> info -> urlTypes
fill identifier - Actually there is no usage at all. you can use anything. only the sceme and role considered.
URL schemes - unique app scheme which other apps use to open the app, cannot use existing ios system schemes in here (https://developer.apple.com/library/content/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007899)
Role -
Editor - schemes if we are defines
Viewer - existing schemes in iOS system (like photo viewer, email , sms apps)
how it works
if we want to open app2 from app1
in app2
identifier - dont know the correct usage. in apple Doc also not gives a full Description
schecme - used iPay
role - Editor (this is our own define scheme. so need to use as Editor. if systemdefine scheme should as view)
in App1
app1 we should also have to define url scheme for matching for appys2. scheme should be same and role should None.
identifier - can use anything
schecme - used iPay
role - None
let kCustomURLScheme = "ipay://" // only the sceme used. not identifier
let customURL = URL(string: customURLScheme)!
if UIApplication.shared.canOpenURL(customURL) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(customURL, completionHandler: { (success) in
print("Open url : \(success)")
})
} else {
UIApplication.shared.openURL(customURL)
}
return true
}
** if we use same scheme for two application
system starts first installed application. if we uninstall first app then it will open second app.
No comments:
Post a Comment