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

Some automations for Android #198

Merged
merged 6 commits into from
Nov 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ tns plugin add nativescript-plugin-firebase
```
_This will guide you through installing additional components. Check the doc links above to see what's what. You can always change your choices later._

### Config
If you choose to save your config during the installation, the supported options may be saved in the `firebase.nativescript.json` at the root of your app.
This is to ensure your app may roundtrip source control and installation on CI won't run the questionary during install.

You can reconfigure the plugin by going to the `node_modules/nativescript-plugin-firebase` and running `npm run config`.

You can also change the configuration by deleting the `firebase.nativescript.json` and reinstalling the plugin.

### iOS
[Looking to automate this step](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/136), but for now, to build with Xcode 8 (iOS 10 SDK), you need to open the Xcode project via the platforms/ios/appname.__xcworkspace__/ file - then select your app's target, capabilities, enable 'Keychain sharing'.

Expand All @@ -57,10 +65,11 @@ We're trying to automate these steps, but for now:
}
```

- Add the very bottom of the same file add
```
apply plugin: "com.google.gms.google-services"
```
#### google-services.json
Firebase configures the native android project using a *google-services.json* file.
You can place it at `app/App_Resources/Android/google-services.json`.

This plugin adds an after-prepare NativeScript CLI hook that will copy it to the native android project at `platforms/android/google-services.json`.

## Usage

Expand Down
22 changes: 21 additions & 1 deletion docs/MESSAGING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,30 @@ Open `app/App_Resources/iOS/Info.plist` and add this to the bottom:
```xml
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
<string>remote-notification</string>
</array>
```

For Android you will not get the title and body if the notification was received while the application was in background, but you will get the *data* payload.
Add the following services in the `app/App_Resources/Android/AndroidManifest.xml` to enable advanced FCM messaging:
```
<manifest ... >
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! Do you think we'd be able to add this to the postinstall script? Not as part of this PR, just would like to know if you think it would be a wise thing to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is ok for the plugins to require some modifications to be done by hand, as long as these modifications can be kept in source control and are well documented.

If the changes happen to be in platforms/* then it would be best if there is an automated way to apply them (using hooks?) so the app can roundtrip source control and continuous integration.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

<application ... >
...
<service android:name="org.nativescript.plugins.firebase.MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<service android:name="org.nativescript.plugins.firebase.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
</application>
</manifest>
```

#### Provisioning hell
Follow [this guide](https://firebase.google.com/docs/cloud-messaging/ios/certs) to the letter. Once you've done it run `tns run ios` and upon starting the app it should prompt you for notification support. That also works on the simulator, but actually receiving notifications is _only_ possible on a real device.

Expand Down
7 changes: 5 additions & 2 deletions firebase.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ var GOOGLE_SIGNIN_INTENT_ID = 123;
if (typeof(com.google.firebase.messaging) === "undefined") {
return;
}
appModule.onLaunch = function(intent) {
appModule.on("launch", function(args) {

var intent = args.android;

var extras = intent.getExtras();
if (extras !== null) {
var result = {
Expand All @@ -40,7 +43,7 @@ var GOOGLE_SIGNIN_INTENT_ID = 123;
});
}
}
};
});

})();

Expand Down
2 changes: 1 addition & 1 deletion firebase.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ firebase.addAppDelegateMethods = function(appDelegate) {
var aps = userInfo.objectForKey("aps");
if (aps !== null) {
var alert = aps.objectForKey("alert");
if (alert !== null) {
if (alert !== null && alert.objectForKey) {
userInfoJSON.title = alert.objectForKey("title");
userInfoJSON.body = alert.objectForKey("body");
}
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "nativescript-plugin-firebase",
"version": "3.7.1",
"description" : "Fire. Base. Firebase!",
"main" : "firebase.js",
"description": "Fire. Base. Firebase!",
"main": "firebase.js",
"typings": "index.d.ts",
"nativescript": {
"platforms": {
Expand All @@ -11,7 +11,8 @@
}
},
"scripts": {
"postinstall": "node scripts/postinstall.js"
"postinstall": "node scripts/postinstall.js",
"config": "node scripts/postinstall.js config"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -40,6 +41,7 @@
},
"homepage": "https://github.com/eddyverbruggen/nativescript-plugin-firebase",
"dependencies": {
"app-root-path": "^2.0.1",
"prompt": "^1.0.0"
}
}
2 changes: 2 additions & 0 deletions platforms/android/include.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ dependencies {
// compile "com.google.android.gms:play-services-auth:9.6.+"

}

apply plugin: "com.google.gms.google-services"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly on my machine this leads to:

* Where:
Script '/Users/eddyverbruggen/sandboxes/_remove/firebasepanayot/platforms/android/configurations/nativescript-plugin-firebase/include.gradle' line: 42

* What went wrong:
A problem occurred evaluating script.
> Plugin with id 'com.google.gms.google-services' not found.

I'm running tns 2.3.0.. perhaps this changed in a more recent version?

Still applying the plugin at the bottom of platforms/android/build.gradle works fine though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'com.google.gms.google-services' plugin still has to be added by hand in the build.gradle, but the apply plugin is now part of the firebase include.gradle.

The 'com.google.gms.google-services' can be somewhat automated using an additional after prepare hook like the one here:

https://github.com/NativeScript/nativescript-marketplace-demo/blob/push-notifications/hooks/after-prepare/firebase.build.gradle.js

But it looks far to fragile for me to push this in the firebase plugin.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you double check if it works when you add by hand this in platform/android:

  dependencies {
    classpath "com.android.tools.build:gradle:X.X.X"
    classpath "com.google.gms:google-services:3.0.0"
  }

Without the:

apply plugin: "com.google.gms.google-services"

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, adding apply plugin: "com.google.gms.google-services" to the bottom is no longer required. Cool!

I see what you mean with the after prepare hook but I think it's worth the brittleness to include it in the plugin. Worst case scenario the developer still needs to add the classpath by hand but generally this would make installation lots easier.

Loading