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

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen authored and eddyverbruggen committed Mar 22, 2017
1 parent 7626136 commit 9fa6f73
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 37 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
<img src="docs/images/firebase-logo.png" width="116px" height="32px" alt="Firebase"/>


## 3.11.0 (2017, March 22)

[Full changelog](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/compare/3.10.2...3.11.0)

### SDK versions

If version numbers __changed__, clean your platform folders to avoid build errors.
Also, for Android update your Google Repository in the Android SDK manager (type `android` on the command prompt),
and for iOS do a `pod repo update` to fetch the latest versions from Cocoapods.

- iOS: 3.13.x
- Android: 10.2.x

### Fixes
- [#304](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/304) IOS cloud notification on click not triggering addOnMessageReceivedCallback
- [#274](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/274) Cleanup AppDelegate call #274




## 3.10.2 (2017, March 12)

[Full changelog](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/compare/3.10.1...3.10.2)
Expand Down
9 changes: 7 additions & 2 deletions docs/MESSAGING.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ so it's not removed when you remove and re-add the iOS platform. The relevant co
<string>development</string>
```

Since plugin version 3.11.0 the plugin will pick up that file during a build and integrates it with the built app
so you no longer need to continually manually enable push notifications in Xcode.

#### Allow processing when a background push is received
Open `app/App_Resources/iOS/Info.plist` and add this to the bottom:

Expand All @@ -61,7 +64,7 @@ Open `app/App_Resources/iOS/Info.plist` and add this to the bottom:
</array>
```

#### Cleanup up an old script
#### Cleanup an old script
Versions up to 3.9.2 of this plugin added the script `/hooks/after-prepare/firebase-install-ios-entitlements.js`, please remove it.

#### Provisioning hell
Expand Down Expand Up @@ -150,10 +153,12 @@ and:
Using the Firebase Console gives you most flexibility, but you can quickly and easily test from the command line as well:

```
curl -X POST --header "Authorization: key=SERVER_KEY" --Header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "{\"notification\":{\"title\": \"My title\", \"text\": \"My text\", \"sound\": \"default\"}, \"data\":{\"foo\":\"bar\"}, \"priority\": \"High\", \"to\": \"DEVICE_TOKEN\"}"
curl -X POST --header "Authorization: key=SERVER_KEY" --Header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "{\"notification\":{\"title\": \"My title\", \"text\": \"My text\", \"badge\": \"1\", \"sound\": \"default\"}, \"data\":{\"foo\":\"bar\"}, \"priority\": \"High\", \"to\": \"DEVICE_TOKEN\"}"
```

* SERVER_KEY: see below
* DEVICE_TOKEN: the one you got in `addOnPushTokenReceivedCallback` or `init`'s `onPushTokenReceivedCallback`

If you don't want a badge on the app icon, remove the `badge` property or set it to 0. Note that launching the app clears the badge anyway.

<img src="images/push-server-key.png" width="459px" height="220px" alt="Push server key"/>
56 changes: 25 additions & 31 deletions firebase.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ firebase.addAppDelegateMethods = function(appDelegate) {
addBackgroundRemoteNotificationHandler(appDelegate);
};

addBackgroundRemoteNotificationHandler(getAppDelegate());

firebase.addOnMessageReceivedCallback = function (callback) {
return new Promise(function (resolve, reject) {
try {
Expand Down Expand Up @@ -225,7 +223,7 @@ firebase._registerForRemoteNotifications = function () {
}
if (firebase._registerForRemoteNotificationsRanThisSession) {
// ignore
return;
// return;
}
firebase._registerForRemoteNotificationsRanThisSession = true;

Expand Down Expand Up @@ -289,6 +287,29 @@ firebase._registerForRemoteNotifications = function () {
}
};

function getAppDelegate() {
// Play nice with other plugins by not completely ignoring anything already added to the appdelegate
if (application.ios.delegate === undefined) {
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};

var appDelegate = (function (_super) {
__extends(appDelegate, _super);
function appDelegate() {
_super.apply(this, arguments);
}
appDelegate.ObjCProtocols = [UIApplicationDelegate];
return appDelegate;
})(UIResponder);
application.ios.delegate = appDelegate;
}
return application.ios.delegate;
}

// rather than hijacking the appDelegate for these we'll be a good citizen and listen to the notifications
function prepAppDelegate() {
if (typeof(FIRMessaging) !== "undefined") {
Expand Down Expand Up @@ -328,29 +349,7 @@ function prepAppDelegate() {
firebase.addAppDelegateMethods(getAppDelegate());
}

function getAppDelegate() {
// Play nice with other plugins by not completely ignoring anything already added to the appdelegate
if (application.ios.delegate === undefined) {
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};

var appDelegate = (function (_super) {
__extends(appDelegate, _super);
function appDelegate() {
_super.apply(this, arguments);
}
firebase.addAppDelegateMethods(appDelegate);
appDelegate.ObjCProtocols = [UIApplicationDelegate];
return appDelegate;
})(UIResponder);
application.ios.delegate = appDelegate;
}
return application.ios.delegate;
}
prepAppDelegate();

firebase.toJsObject = function(objCObj) {
if (objCObj === null || typeof objCObj != "object") {
Expand Down Expand Up @@ -423,8 +422,6 @@ firebase.init = function (arg) {
function runInit() {
arg = arg || {};

prepAppDelegate();

// this requires you to download GoogleService-Info.plist and
// it to app/App_Resources/iOS/, see https://firebase.google.com/support/guides/firebase-ios
FIRApp.configure();
Expand Down Expand Up @@ -496,9 +493,6 @@ firebase.init = function (arg) {
resolve(firebase.instance);
}

// wrapped in a timeout to play nice with nativescript-angular's appdelegate handling,
// but reverted because of #272
// setTimeout(runInit, 0);
runInit();
} catch (ex) {
console.log("Error in firebase.init: " + ex);
Expand Down
23 changes: 19 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
{
"name": "nativescript-plugin-firebase",
"version": "3.10.2",
"version": "3.11.0",
"description": "Fire. Base. Firebase!",
"main": "firebase",
"typings": "index.d.ts",
"nativescript": {
"platforms": {
"android": "2.3.0",
"ios": "2.3.0"
}
},
"hooks": [
{
"type": "before-prepare",
"script": "scripts/entitlements-before-prepare.js",
"inject": true
},
{
"type": "after-prepare",
"script": "scripts/entitlements-after-prepare.js",
"inject": true
}
]
},
"scripts": {
"bundle-installer": "npm install --ignore-scripts && webpack --config scripts/webpack.config.js scripts/installer.js scripts/postinstall.js",
"prepublish": "npm run bundle-installer",
"postinstall": "node scripts/postinstall.js",
"postinstall": "node postinstall-hooks.js && node scripts/postinstall.js",
"preuninstall": "node preuninstall-hooks.js",
"setup": "node scripts/postinstall.js setup",
"config": "node scripts/postinstall.js config"
},
Expand Down Expand Up @@ -48,7 +61,9 @@
"homepage": "https://github.com/eddyverbruggen/nativescript-plugin-firebase",
"dependencies": {
"xcode": "0.8.0",
"prompt-lite": "^0.1.1"
"prompt-lite": "^0.1.1",
"fs-promise": "^2.0.0",
"nativescript-hook": "^0.2.1"
},
"devDependencies": {
"prompt-lite": "^0.1.1",
Expand Down
1 change: 1 addition & 0 deletions postinstall-hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('nativescript-hook')(__dirname).postinstall();
1 change: 1 addition & 0 deletions preuninstall-hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('nativescript-hook')(__dirname).preuninstall();
25 changes: 25 additions & 0 deletions scripts/entitlements-after-prepare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var fs = require('fs-extra');
var path = require('path');

module.exports = function (logger, platformsData, projectData, hookArgs) {
var platform = hookArgs.platform.toLowerCase(),
appResourcesDirectoryPath = projectData.appResourcesDirectoryPath,
entitlementsFile = path.join(appResourcesDirectoryPath, "iOS", projectData.projectName + ".entitlements"),
projectRoot = path.join(projectData.platformsDir, "ios"),
project = path.join(projectRoot, projectData.projectName);

return new Promise(function (resolve, reject) {
if (platform == 'ios') {
fs.exists(entitlementsFile, function (exists) {
if (!exists) return reject(); //Error("entitlementsFile: `" + entitlementsFile + "` not found"));
var dest = path.join(project, projectData.projectName + ".entitlements");
fs.copy(entitlementsFile, dest, function (error) {
if (error) return reject(error);
resolve();
});
})
} else {
resolve();
}
});
};
25 changes: 25 additions & 0 deletions scripts/entitlements-before-prepare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var fs = require('fs-extra');
var path = require('path');

module.exports = function (logger, platformsData, projectData, hookArgs) {
var platform = hookArgs.platform.toLowerCase(),
appResourcesDirectoryPath = projectData.appResourcesDirectoryPath,
platformResourcesDirectory = path.join(appResourcesDirectoryPath, 'iOS');

return new Promise(function (resolve, reject) {
if (platform == 'ios') {
var target = path.join(platformResourcesDirectory, 'build.xcconfig');

try {
var buildData = fs.readFileSync(target).toString();
if(!buildData.toString().match(/^\s*CODE_SIGN_ENTITLEMENTS/mg)){
fs.appendFileSync(target, '\nCODE_SIGN_ENTITLEMENTS = ' + path.join(projectData.projectName, projectData.projectName + '.entitlements'));
}
} catch (error) {
reject();
}
}

resolve();
});
};

0 comments on commit 9fa6f73

Please sign in to comment.