I'm currently developing a framework in Swift and I have to check if the app has been opened through a url scheme. To do so I add this into my appdelegate file when developing an app :
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
print("went back")
return true
}
The thing is that UIApplication cannot be imported in a framework. Is there a way to catch that event without having to do it in the app ?
Thx !
There is no universal way to do that. For example there is no iOS default notification which is posted in this case and can be observed.
I see 2 ways of implementing it:
1) Redirect method call (Probably as you did). VK SDK implemented redirection this way.
For example:
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool
{
let result = MySDK.sharedInstance().openURL(url, options: options)
reutrn result
}
Pros: Explicit, developers will know where your SDK handles "open url".
Cons: You need developers to know that they need to add this line of code
2) Create Base App Delegate (Facebook SDK uses this approach). So you create base class which implements this method and force developers to use it as a super class of their AppDelegate
class BaseAppDelegate: UIResponder, UIApplicationDelegate {
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool
{
let result = MySDK.sharedInstance().openURL(url, options: options)
reutrn result
}
}
class MyAppDelegate: BaseAppDelegate {
// Implement some custom app delegate
}
Pros: Easier to implement by developers.
Cons: Not so explicit as previous approach, if this method will be overriden by MyAppDelegate
, super needs to be called.