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

Commit 783e194

Browse files
#478 Invites on Android: AppInviteApi has been deprecated
#479 Is anybody using the invites part? I can't get the deeplink or invitation id.
1 parent ceb4ea5 commit 783e194

File tree

12 files changed

+379
-222
lines changed

12 files changed

+379
-222
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
[Firebase iOS SDK Changelog](https://firebase.google.com/support/release-notes/ios)
44
[Firebase Android SDK Changelog](https://firebase.google.com/support/release-notes/android)
55

6+
## 4.1.0 (2017, September 8)
7+
8+
### New
9+
10+
611
## 4.0.6 (2017, August 23)
712

813
### New

README.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ For readability the supported features have been moved to their own README's:
2626
* [Storage](docs/STORAGE.md)
2727
* [Crash Reporting](docs/CRASHREPORTING.md)
2828
* [Analytics](docs/ANALYTICS.md)
29-
* [Invites](docs/INVITES.md)
29+
* [Invites and Dynamic Links](docs/INVITES_DYNAMICLINKS.md)
3030
* [AdMob](docs/ADMOB.md)
3131

3232
## Prerequisites
@@ -74,9 +74,6 @@ You can also change the configuration by deleting the `firebase.nativescript.jso
7474
### iOS
7575
The Firebase iOS SDK is installed via Cocoapods, so run `pod repo update` to ensure you have the latest spec.
7676

77-
### Android
78-
Install the latest packages 'Google Play Services' and 'Google Repository' in your [Android SDK Manager](http://stackoverflow.com/a/37310513)
79-
8077
#### Google Play Services Version
8178
The plugin will default to version 10.0+ of the Android `play-services-base` SDK.
8279
If you need to change the version (to for instance the latest version), you can add a project ext property `googlePlayServicesVersion` like so:
@@ -226,16 +223,12 @@ Another possible error is "FirebaseApp with name [DEFAULT] doesn't exist." which
226223
placing `google-services.json` to `platforms/android/google-services.json` (see above), and making
227224
the changes to `build.gradle` which are mentioned above as well.
228225

229-
#### Could not find any version that matches com.google.android.gms:play-services-auth:11.0.+.
230-
That means making sure you have the latest `Google Repository` bits installed.
226+
#### Errors regarding API level 26.0.0
227+
Update your local Android SDKs:
231228

232229
Just run `$ANDROID_HOME/tools/bin/sdkmanager --update` from a command prompt
233230
or launch the SDK manager from Android Studio, expand `Extras` and install any pending updates.
234231

235-
Also, an error like "Could not find com.google.firebase:firebase-core:10.0.0" can be caused by having
236-
more than one version of the Android SDK installed. Make sure ANDROID_HOME is set to the Android SDK directory
237-
that is being updated otherwise it will seem as though your updates have no effect.
238-
239232
#### Found play-services:10.A.B, but version 11.X.Y is needed..
240233
Update your Android bits like the issue above and reinstall the android platform in your project.
241234

@@ -248,12 +241,12 @@ android {
248241
// other stuff here
249242
250243
project.ext {
251-
googlePlayServicesVersion = "11.0.+"
244+
googlePlayServicesVersion = "11.2.+"
252245
}
253246
}
254247
```
255248

256-
Where `"11.0.+"` is best set to the same value as the version on [this line](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/platforms/android/include.gradle#L23).
249+
Where `"11.2.+"` is best set to the same value as the `firebase-core` dependency version in [this file](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/platforms/android/include.gradle).
257250

258251
## Credits
259252
The starting point for this plugin was [this great Gist](https://gist.github.com/jbristowe/c89a7bcae7fc9a035ee7) by [John Bristowe](https://github.com/jbristowe).

docs/INVITES.md renamed to docs/INVITES_DYNAMICLINKS.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,63 @@ Open `app/App_Resources/iOS/Info.plist` and add this somewhere in the file (if i
2121
<string>For inviting others to use this app.</string>
2222
```
2323

24+
## Receiving Dynamic Links
25+
26+
### Android
27+
To have a dynamic link open your app you need to add an Intent filter to the `<activity>` in `app/App_Resources/Android/AndroidManifest.xml`:
28+
29+
```xml
30+
<intent-filter>
31+
<action android:name="android.intent.action.VIEW"/>
32+
<category android:name="android.intent.category.DEFAULT"/>
33+
<category android:name="android.intent.category.BROWSABLE"/>
34+
<data android:host="www.coolapp.com" android:scheme="http"/><!-- Change this -->
35+
<data android:host="www.coolapp.com" android:scheme="https"/><!-- .. and this! -->
36+
</intent-filter>
37+
```
38+
39+
### iOS
40+
> We may automate parts of this later, but for now you'll need to do it by hand.
41+
42+
On iOS you'll need to add a custom URL scheme to `app/App_Resources/iOS/Info.plist` (if you don't have this one already):
43+
44+
```xml
45+
<key>CFBundleURLTypes</key>
46+
<array>
47+
<dict>
48+
<key>CFBundleTypeRole</key>
49+
<string>Editor</string>
50+
<key>CFBundleURLName</key>
51+
<string>firebaseplugin.deeplink.urlscheme</string><!-- anything you like, but must be unique -->
52+
<key>CFBundleURLSchemes</key>
53+
<array>
54+
<string>org.nativescript.firebasedemo</string><!-- the same as your bundle id (nativescript.id in package.json) -->
55+
</array>
56+
</dict>
57+
</array>
58+
```
59+
60+
Now open the project in Xcode (the `platforms/ios/<projectname>.xcworkspace` file!) and in the Capabilities tab
61+
enable Associated Domains and add the following to the Associated Domains list:
62+
63+
```
64+
applinks:app_code.app.goo.gl
65+
```
66+
67+
Where `app_code` can be found in the Firebase console at the Dynamic Links section.
68+
69+
#### Copy the entitlements file
70+
The previous step created a the file`platforms/ios/YourAppName/(Resources/)YourAppName.entitlements`.
71+
Copy that file to `app/App_Resources/iOS/` (if it doesn't exist yet, otherwise merge its contents),
72+
so it's not removed when you remove and re-add the iOS platform. The relevant content looks like this:
73+
74+
```xml
75+
<key>com.apple.developer.associated-domains</key>
76+
<array>
77+
<string>applinks:j4ctx.app.goo.gl</string>
78+
</array>
79+
```
80+
2481
## Functions
2582

2683
### invites.sendInvitation
@@ -64,4 +121,27 @@ firebase.invites.getInvitation().then(
64121
console.log("getInvitation error: " + error);
65122
}
66123
);
124+
```
125+
126+
### addOnDynamicLinkReceivedCallback / init.onDynamicLinkCallback
127+
When your app is launched from a dynamic link, you may want to capture that link and perform some action.
128+
129+
You can either add an `onDynamicLinkCallback` callback to `init`, or use `addOnDynamicLinkReceivedCallback`:
130+
131+
```js
132+
firebase.init({
133+
onDynamicLinkCallback: function (url) {
134+
console.log("Dynamic Link: " + url); // this is a string, like http://mydomain.com/applink
135+
}
136+
});
137+
```
138+
139+
.. or:
140+
141+
```js
142+
firebase.addOnDynamicLinkReceivedCallback(
143+
function (url) {
144+
// ..
145+
}
146+
);
67147
```

firebase-common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ firebase.storage = null;
7373
firebase.firebaseRemoteConfig = null;
7474
firebase.authStateListeners = [];
7575
firebase._receivedNotificationCallback = null;
76-
firebase._DynamicLinkCallback = null;
76+
firebase._dynamicLinkCallback = null;
7777

7878
firebase.addAuthStateListener = function (listener) {
7979
if (firebase.authStateListeners.indexOf(listener) === -1) {

firebase.android.js

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

77
firebase._launchNotification = null;
8+
firebase._launchDynamicLink = null;
89

910
// we need to cache and restore the context, otherwise the next invocation is broken
1011
firebase._rememberedContext = null;
@@ -32,42 +33,63 @@ var messagingEnabled = new lazy(function () {
3233
return typeof(com.google.firebase.messaging) !== "undefined"
3334
});
3435

36+
var dynamicLinksEnabled = new lazy(function () {
37+
return typeof(com.google.android.gms.appinvite) !== "undefined"
38+
});
39+
3540
(function () {
3641
appModule.on("launch", function (args) {
37-
if (!messagingEnabled()) {
38-
return;
39-
}
40-
4142
var intent = args.android;
43+
var isLaunchIntent = "android.intent.action.VIEW" === intent.getAction();
4244

43-
var extras = intent.getExtras();
44-
if (extras !== null) {
45-
var result = {
46-
foreground: false,
47-
data: {}
48-
};
45+
if (!isLaunchIntent && messagingEnabled()) {
46+
var extras = intent.getExtras();
47+
if (extras !== null) {
48+
var result = {
49+
foreground: false,
50+
data: {}
51+
};
4952

50-
var iterator = extras.keySet().iterator();
51-
while (iterator.hasNext()) {
52-
var key = iterator.next();
53-
if (key !== "from" && key !== "collapse_key") {
54-
result[key] = extras.get(key);
55-
result.data[key] = extras.get(key);
53+
var iterator = extras.keySet().iterator();
54+
while (iterator.hasNext()) {
55+
var key = iterator.next();
56+
if (key !== "from" && key !== "collapse_key") {
57+
result[key] = extras.get(key);
58+
result.data[key] = extras.get(key);
59+
}
5660
}
57-
}
5861

59-
// in case this was a cold start we don't have the _receivedNotificationCallback yet
60-
if (firebase._receivedNotificationCallback === null) {
61-
firebase._launchNotification = result;
62-
} else {
63-
// add a little delay just to make sure clients alerting this message will see it as the UI needs to settle
64-
setTimeout(function () {
65-
firebase._receivedNotificationCallback(result);
66-
});
62+
if (firebase._receivedNotificationCallback === null) {
63+
firebase._launchNotification = result;
64+
} else {
65+
// add a little delay just to make sure clients alerting this message will see it as the UI needs to settle
66+
setTimeout(function () {
67+
firebase._receivedNotificationCallback(result);
68+
});
69+
}
6770
}
71+
72+
} else if (isLaunchIntent && dynamicLinksEnabled()) {
73+
var intent = args.android;
74+
75+
var getDynamicLinksCallback = new com.google.android.gms.tasks.OnCompleteListener({
76+
onComplete: function (task) {
77+
if (task.isSuccessful() && task.getResult() !== null) {
78+
result = task.getResult().getLink().toString();
79+
if (firebase._dynamicLinkCallback === null) {
80+
firebase._launchDynamicLink = result;
81+
} else {
82+
setTimeout(function () {
83+
firebase._dynamicLinkCallback(firebase.toJsObject(result));
84+
});
85+
}
86+
}
87+
}
88+
});
89+
var firebaseDynamicLinks = com.google.firebase.dynamiclinks.FirebaseDynamicLinks.getInstance();
90+
firebaseDynamicLinks.getDynamicLink(intent).addOnCompleteListener(getDynamicLinksCallback);
6891
}
6992
});
70-
7193
})();
7294

7395
firebase.toHashMap = function (obj) {
@@ -177,7 +199,6 @@ firebase.authStateListener = null;
177199

178200
firebase.init = function (arg) {
179201
return new Promise(function (resolve, reject) {
180-
181202
function runInit() {
182203
if (firebase.instance !== null) {
183204
reject("You already ran init");
@@ -237,11 +258,11 @@ firebase.init = function (arg) {
237258
firebase.addOnPushTokenReceivedCallback(arg.onPushTokenReceivedCallback);
238259
}
239260
}
240-
241-
// Firebase DynamicLink
242-
if (arg.onDynamicLinkCallback !== undefined){
243-
firebase.addOnDynamicLinkReceivedCallback(arg.onDynamicLinkCallback);
244-
}
261+
262+
// Firebase DynamicLink
263+
if (arg.onDynamicLinkCallback !== undefined) {
264+
firebase.addOnDynamicLinkReceivedCallback(arg.onDynamicLinkCallback);
265+
}
245266

246267
// Firebase storage
247268
if (arg.storageBucket) {
@@ -362,6 +383,30 @@ firebase.addOnMessageReceivedCallback = function (callback) {
362383
});
363384
};
364385

386+
firebase.addOnDynamicLinkReceivedCallback = function (callback) {
387+
return new Promise(function (resolve, reject) {
388+
try {
389+
if (typeof(com.google.android.gms.appinvite) === "undefined") {
390+
reject("Uncomment invites in the plugin's include.gradle first");
391+
return;
392+
}
393+
394+
firebase._dynamicLinkCallback = callback;
395+
396+
// 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;
400+
}
401+
402+
resolve();
403+
} catch (ex) {
404+
console.log("Error in firebase.addOnDynamicLinkReceivedCallback: " + ex);
405+
reject(ex);
406+
}
407+
});
408+
};
409+
365410
firebase.addOnPushTokenReceivedCallback = function (callback) {
366411
return new Promise(function (resolve, reject) {
367412
try {
@@ -2073,8 +2118,7 @@ firebase.invites.getInvitation = function () {
20732118
}
20742119
});
20752120

2076-
var autoLaunchDeepLink = false;
2077-
var activity = appModule.android.foregroundActivity;
2121+
// var autoLaunchDeepLink = false;
20782122

20792123
firebase._mGoogleApiClient = new com.google.android.gms.common.api.GoogleApiClient.Builder(com.tns.NativeScriptApplication.getInstance())
20802124
.addOnConnectionFailedListener(onConnectionFailedListener)
@@ -2111,7 +2155,7 @@ firebase.invites.getInvitation = function () {
21112155
}
21122156
});
21132157

2114-
firebaseDynamicLinks.getDynamicLink(activity.getIntent())
2158+
firebaseDynamicLinks.getDynamicLink(appModule.android.startActivity.getIntent())
21152159
.addOnSuccessListener(onSuccessListener)
21162160
.addOnFailureListener(onFailureListener);
21172161

@@ -2123,59 +2167,4 @@ firebase.invites.getInvitation = function () {
21232167
});
21242168
};
21252169

2126-
2127-
firebase.addOnDynamicLinkReceivedCallback = function (callback) {
2128-
return new Promise(function (resolve, reject) {
2129-
try {
2130-
if (typeof(com.google.android.gms.appinvite) === "undefined") {
2131-
reject("Uncomment invites in the plugin's include.gradle first");
2132-
return;
2133-
}
2134-
2135-
firebase._DynamicLinkCallback = callback;
2136-
resolve();
2137-
} catch (ex) {
2138-
console.log("Error in firebase.addOnDynamicLinkReceivedCallback: " + ex);
2139-
reject(ex);
2140-
}
2141-
});
2142-
};
2143-
2144-
var dynamicLinksEnabled = new lazy(function () {
2145-
return typeof(com.google.android.gms.appinvite) !== "undefined"
2146-
});
2147-
2148-
(function() {
2149-
appModule.on("launch", function(args) {
2150-
if (!dynamicLinksEnabled()) {
2151-
return;
2152-
}
2153-
2154-
var intent = args.android;
2155-
2156-
var getDynamicLinksCallback = new com.google.android.gms.tasks.OnCompleteListener({
2157-
onComplete: function(task) {
2158-
2159-
if (task.isSuccessful() && task.getResult() != null) {
2160-
result = task.getResult().getLink();
2161-
result = firebase.toJsObject(result);
2162-
if(firebase._DynamicLinkCallback === null){
2163-
console.log("No callback is provided for a dynamic link");
2164-
}
2165-
else{
2166-
setTimeout(function() {
2167-
firebase._DynamicLinkCallback(result);
2168-
});
2169-
}
2170-
2171-
}
2172-
}
2173-
});
2174-
2175-
firebaseDynamicLinks = com.google.firebase.dynamiclinks.FirebaseDynamicLinks.getInstance();
2176-
DynamicLinks = firebaseDynamicLinks.getDynamicLink(intent).addOnCompleteListener(getDynamicLinksCallback);
2177-
2178-
});
2179-
})()
2180-
21812170
module.exports = firebase;

0 commit comments

Comments
 (0)