Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit e69659e

Browse files
committed
Fixed bugs in invite and dynamic links implementations
Added proper iOS 9+ handling for dynamic links Extended returned data to include match confidence (specific for iOS) Updated documentation
1 parent 1edc56f commit e69659e

4 files changed

Lines changed: 104 additions & 30 deletions

File tree

docs/INVITES_DYNAMICLINKS.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Since plugin version 3.12.0 you can use Firebase _Invites_ features.
55

66
_Invites_ lets you invite other users to your app from right within your own app, via SMS and/or Email.
77

8+
Keep in mind that invites are based of dynamic links, and so calling for an invite may return a plain dynamic link, in which case invitationId is null.
9+
810
### Android
911
* [Make sure you've uploaded your SHA1 fingerprint(s)](https://developers.google.com/android/guides/client-auth) to the Firebase console, then download the latest `google-services.json` file and add it to `app/App_Resources/Android`.
1012

@@ -110,12 +112,12 @@ The options you can pass to `sendInvitation` are:
110112

111113

112114
### invites.getInvitation
113-
When the user opens your app from an invite, you can retrieve the details via the `getInvitation` function:
115+
When the user opens your app from an invite or a dynamic link, you can retrieve the details via the `getInvitation` function after you initialize Firebase:
114116

115117
```js
116118
firebase.invites.getInvitation().then(
117119
function (result) { // GetInvitationResult
118-
console.log("deeplink: " + result.deeplink + ", invitationId: " + result.invitationId);
120+
console.log("deepLink: " + result.deepLink + ", invitationId: " + result.invitationId+ ", matchType: "+ result.matchType);
119121
},
120122
function (error) {
121123
console.log("getInvitation error: " + error);
@@ -130,8 +132,8 @@ You can either add an `onDynamicLinkCallback` callback to `init`, or use `addOnD
130132

131133
```js
132134
firebase.init({
133-
onDynamicLinkCallback: function (url) {
134-
console.log("Dynamic Link: " + url); // this is a string, like http://mydomain.com/applink
135+
onDynamicLinkCallback: function (result) {
136+
console.log("Dynamic Link: " + result.url+ ", matchConfidence: "+ result.matchConfidence);
135137
}
136138
});
137139
```
@@ -144,4 +146,4 @@ You can either add an `onDynamicLinkCallback` callback to `init`, or use `addOnD
144146
// ..
145147
}
146148
);
147-
```
149+
```

firebase.android.js

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var fs = require("file-system");
55
var firebase = require("./firebase-common");
66

77
firebase._launchNotification = null;
8-
firebase._launchDynamicLink = null;
8+
firebase._cachedDynamicLink = null;
99

1010
// we need to cache and restore the context, otherwise the next invocation is broken
1111
firebase._rememberedContext = null;
@@ -75,12 +75,20 @@ var dynamicLinksEnabled = new lazy(function () {
7575
var getDynamicLinksCallback = new com.google.android.gms.tasks.OnCompleteListener({
7676
onComplete: function (task) {
7777
if (task.isSuccessful() && task.getResult() !== null) {
78-
result = task.getResult().getLink().toString();
78+
var result = task.getResult();
7979
if (firebase._dynamicLinkCallback === null) {
80-
firebase._launchDynamicLink = result;
81-
} else {
80+
firebase._cachedDynamicLink = {
81+
url: result.getLink().toString(),
82+
matchConfidence: 1,
83+
minimumAppVersion: result.getMinimumAppVersion()
84+
};
85+
} else {
8286
setTimeout(function () {
83-
firebase._dynamicLinkCallback(firebase.toJsObject(result));
87+
firebase._dynamicLinkCallback({
88+
url: result.getLink().toString(),
89+
matchConfidence: 1,
90+
minimumAppVersion: result.getMinimumAppVersion()
91+
});
8492
});
8593
}
8694
}
@@ -394,9 +402,9 @@ firebase.addOnDynamicLinkReceivedCallback = function (callback) {
394402
firebase._dynamicLinkCallback = callback;
395403

396404
// if the app was launched from a dynamic link, process it now
397-
if (firebase._launchDynamicLink !== null) {
398-
callback(firebase._launchDynamicLink);
399-
firebase._launchDynamicLink = null;
405+
if (firebase._cachedDynamicLink !== null) {
406+
callback(firebase._cachedDynamicLink);
407+
firebase._cachedDynamicLink = null;
400408
}
401409

402410
resolve();
@@ -2110,18 +2118,17 @@ firebase.invites.getInvitation = function () {
21102118

21112119
var onConnectionFailedListener = new com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener({
21122120
onConnectionFailed: function (connectionResult) {
2113-
reject(connectionResult.getErrorMessage());
2121+
// we shouldn't reject on connection failure as the invitation link may still be available locally
2122+
// reject(connectionResult.getErrorMessage());
21142123
}
21152124
});
21162125

2117-
// var autoLaunchDeepLink = false;
2118-
2119-
firebase._mGoogleApiClient = new com.google.android.gms.common.api.GoogleApiClient.Builder(com.tns.NativeScriptApplication.getInstance())
2126+
firebase._mGoogleInviteApiClient = new com.google.android.gms.common.api.GoogleApiClient.Builder(com.tns.NativeScriptApplication.getInstance())
21202127
.addOnConnectionFailedListener(onConnectionFailedListener)
21212128
.addApi(com.google.android.gms.appinvite.AppInvite.API)
21222129
.build();
21232130

2124-
firebase._mGoogleApiClient.connect();
2131+
firebase._mGoogleInviteApiClient.connect();
21252132

21262133
var firebaseDynamicLinks = com.google.firebase.dynamiclinks.FirebaseDynamicLinks.getInstance();
21272134

@@ -2140,6 +2147,7 @@ firebase.invites.getInvitation = function () {
21402147

21412148
resolve({
21422149
deepLink: deepLinkUri === null ? null : deepLinkUri.toString(),
2150+
matchType: deepLinkUri === null ? null : 1,
21432151
invitationId: firebaseAppInvite.getInvitationId() // string | null
21442152
});
21452153
}
@@ -2163,4 +2171,4 @@ firebase.invites.getInvitation = function () {
21632171
});
21642172
};
21652173

2166-
module.exports = firebase;
2174+
module.exports = firebase;

firebase.d.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,11 @@ export module analytics {
710710
// Invites module
711711
export module invites {
712712

713+
export enum MATCH_TYPE {
714+
WEAK,
715+
STRONG
716+
}
717+
713718
export interface SendInvitationOptions {
714719
/**
715720
* Invitation title you want to send.
@@ -753,15 +758,29 @@ export module invites {
753758
}
754759

755760
export interface GetInvitationResult {
756-
deeplink: any;
757-
invitationId: any;
761+
deepLink: string;
762+
matchType?: MATCH_TYPE,
763+
invitationId: string;
758764
}
759765

760766
function sendInvitation(options: SendInvitationOptions): Promise<SendInvitationResult>;
761767

762768
function getInvitation(): Promise<GetInvitationResult>;
763769
}
764770

771+
export module dynamicLinks {
772+
export enum MATCH_CONFIDENCE {
773+
WEAK,
774+
STRONG
775+
}
776+
777+
export interface DynamicLinkCallbackData {
778+
url: string;
779+
matchConfidence?: MATCH_CONFIDENCE,
780+
minimumAppVersion?: string;
781+
}
782+
}
783+
765784
// Auth
766785
export function login(options: LoginOptions): Promise<User>;
767786

@@ -801,7 +820,7 @@ export function addOnPushTokenReceivedCallback(onPushTokenReceived: (data: strin
801820
export function getCurrentPushToken(): Promise<string>;
802821

803822
// dynamic links
804-
export function addOnDynamicLinkReceivedCallback(onDynamicLinkReceived: (url: string) => void): Promise<any>;
823+
export function addOnDynamicLinkReceivedCallback(onDynamicLinkReceived: (callBackData: dynamicLinks.DynamicLinkCallbackData) => void): Promise<any>;
805824

806825
// remote config
807826
export function getRemoteConfig(options: GetRemoteConfigOptions): Promise<GetRemoteConfigResult>;

firebase.ios.js

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ function addBackgroundRemoteNotificationHandler(appDelegate) {
6868
appDelegate.prototype.applicationDidReceiveRemoteNotificationFetchCompletionHandler = function (app, notification, completionHandler) {
6969

7070
firebase._configure();
71-
72-
// Pass notification to auth and check if they can handle it (in case phone auth is being used), see https://firebase.google.com/docs/auth/ios/phone-auth
71+
72+
// Pass notification to auth and check if they can handle it (in case phone auth is being used), see https://firebase.google.com/docs/auth/ios/phone-auth
7373
if (FIRAuth.auth().canHandleNotification(notification)) {
7474
completionHandler(UIBackgroundFetchResultNoData);
7575
return;
@@ -114,8 +114,9 @@ firebase.addAppDelegateMethods = function (appDelegate) {
114114
var receivedInvite = FIRInvites.handleURLSourceApplicationAnnotation(url, sourceApplication, annotation);
115115
if (receivedInvite) {
116116
console.log("Deep link from " + sourceApplication + ", Invite ID: " + invite.invideId + ", App URL: " + invite.deepLink);
117-
this._cachedInvitation = {
117+
firebase._cachedInvitation = {
118118
deepLink: invite.deepLink,
119+
matchType: invite.matchType,
119120
invitationId: invite.invideId
120121
};
121122
result = true;
@@ -125,7 +126,12 @@ firebase.addAppDelegateMethods = function (appDelegate) {
125126
if (typeof(FIRDynamicLink) !== "undefined") {
126127
var dynamicLink = FIRDynamicLinks.dynamicLinks().dynamicLinkFromCustomSchemeURL(url)
127128
if (dynamicLink) {
128-
this._cachedDeepLink = dynamicLink.url.absoluteString;
129+
console.log(">>> dynamicLink.url.absoluteString: " + dynamicLink.url.absoluteString);
130+
firebase._cachedDynamicLink = {
131+
url: dynamicLink.url.absoluteString,
132+
matchConfidence: dynamicLink.matchConfidence,
133+
minimumAppVersion: dynamicLink.minimumAppVersion
134+
};
129135
result = true;
130136
}
131137
}
@@ -157,10 +163,18 @@ firebase.addAppDelegateMethods = function (appDelegate) {
157163
if (dynamicLink) {
158164
if (dynamicLink.url !== null) {
159165
console.log(">>> dynamicLink.url.absoluteString: " + dynamicLink.url.absoluteString);
160-
if (this._dynamicLinkCallback) {
161-
this._dynamicLinkCallback(dynamicLink.url.absoluteString);
166+
if (firebase._dynamicLinkCallback) {
167+
firebase._dynamicLinkCallback({
168+
url: dynamicLink.url.absoluteString,
169+
matchConfidence: dynamicLink.matchConfidence,
170+
minimumAppVersion: dynamicLink.minimumAppVersion
171+
});
162172
} else {
163-
this._cachedDeepLink = dynamicLink.url.absoluteString;
173+
firebase._cachedDynamicLink = {
174+
url: dynamicLink.url.absoluteString,
175+
matchConfidence: dynamicLink.matchConfidence,
176+
minimumAppVersion: dynamicLink.minimumAppVersion
177+
};
164178
}
165179
result = true;
166180
}
@@ -171,6 +185,37 @@ firebase.addAppDelegateMethods = function (appDelegate) {
171185
};
172186
}
173187

188+
if (typeof(FIRDynamicLink) !== "undefined") {
189+
appDelegate.prototype.applicationContinueUserActivityRestorationHandler = function (application, userActivity, restorationHandler) {
190+
var result = false;
191+
192+
if (typeof(FIRDynamicLink) !== "undefined" ) {
193+
if (userActivity.webpageURL) {
194+
result = FIRDynamicLinks.dynamicLinks().handleUniversalLinkCompletion(userActivity.webpageURL, function(dynamicLink, error){
195+
if (dynamicLink.url !== null) {
196+
console.log(">>> dynamicLink.url.absoluteString: " + dynamicLink.url.absoluteString);
197+
if (firebase._dynamicLinkCallback) {
198+
firebase._dynamicLinkCallback({
199+
url: dynamicLink.url.absoluteString,
200+
matchConfidence: dynamicLink.matchConfidence,
201+
minimumAppVersion: dynamicLink.minimumAppVersion
202+
});
203+
} else {
204+
firebase._cachedDynamicLink = {
205+
url: dynamicLink.url.absoluteString,
206+
matchConfidence: dynamicLink.matchConfidence,
207+
minimumAppVersion: dynamicLink.minimumAppVersion
208+
};
209+
}
210+
}
211+
})
212+
}
213+
}
214+
215+
return result;
216+
};
217+
}
218+
174219
addBackgroundRemoteNotificationHandler(appDelegate);
175220
};
176221

@@ -586,7 +631,7 @@ firebase.init = function (arg) {
586631
}
587632

588633
firebase._configure();
589-
634+
590635
if (arg.persist) {
591636
FIRDatabase.database().persistenceEnabled = true;
592637
}

0 commit comments

Comments
 (0)