I am using firebase invite to invite friends using referral code. And I need to know how can I handle the following scenarios in my iOS application.
I have followed this guide for Firebase Invite implementation.
Case 1: Application not installed on iPhone and user installs the app via invite. I need referral code from the "deeplink"
parameter set from invitee. or Application installed and currently not running user clicks on invite url from email.
Solution >> As of my knowledge below code inside didFinishLaunchingWithOptions
method will handle this scenario.
if let inviteUrl = launchOptions?[UIApplicationLaunchOptionsURLKey] as? NSURL {
//App opened from invite url
self.handleFirebaseInviteDeeplink(inviteUrl)
}
Case 2: Application already installed and currently running on iPhone and user clicks on invite link inside the email.
Solution >> Below methods in AppDelegate will handle the code I assume.
@available(iOS 9.0, *)
func application(application: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
return self.application(application, openURL: url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String, annotation: "")
}
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
if let invite = FIRInvites.handleURL(url, sourceApplication:sourceApplication, annotation:annotation) as? FIRReceivedInvite {
let matchType = (invite.matchType == FIRReceivedInviteMatchType.Weak) ? "Weak" : "Strong"
print("\n------------------Invite received from: \(sourceApplication) Deeplink: \(invite.deepLink)," + "Id: \(invite.inviteId), Type: \(matchType)")
if (matchType == "Strong") {
print("\n-------------- Invite Deep Link = \(invite.deepLink)")
if !invite.deepLink.isEmpty {
let url = NSURL(string: invite.deepLink)
self.handleFirebaseInviteDeeplink(url!)
}
}
return true
}
return GIDSignIn.sharedInstance().handle(url, sourceApplication: sourceApplication, annotation: annotation)
}
The problem is I couldn't find a way to test any of the scenario. Can anyone point me in the right direction.
Thanks for the help.