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

Commit 9fa6f73

Browse files
EddyVerbruggeneddyverbruggen
authored andcommitted
1 parent 7626136 commit 9fa6f73

File tree

8 files changed

+123
-37
lines changed

8 files changed

+123
-37
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
<img src="docs/images/firebase-logo.png" width="116px" height="32px" alt="Firebase"/>
22

33

4+
## 3.11.0 (2017, March 22)
5+
6+
[Full changelog](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/compare/3.10.2...3.11.0)
7+
8+
### SDK versions
9+
10+
If version numbers __changed__, clean your platform folders to avoid build errors.
11+
Also, for Android update your Google Repository in the Android SDK manager (type `android` on the command prompt),
12+
and for iOS do a `pod repo update` to fetch the latest versions from Cocoapods.
13+
14+
- iOS: 3.13.x
15+
- Android: 10.2.x
16+
17+
### Fixes
18+
- [#304](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/304) IOS cloud notification on click not triggering addOnMessageReceivedCallback
19+
- [#274](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/274) Cleanup AppDelegate call #274
20+
21+
22+
23+
424
## 3.10.2 (2017, March 12)
525

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

docs/MESSAGING.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ so it's not removed when you remove and re-add the iOS platform. The relevant co
5151
<string>development</string>
5252
```
5353

54+
Since plugin version 3.11.0 the plugin will pick up that file during a build and integrates it with the built app
55+
so you no longer need to continually manually enable push notifications in Xcode.
56+
5457
#### Allow processing when a background push is received
5558
Open `app/App_Resources/iOS/Info.plist` and add this to the bottom:
5659

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

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

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

152155
```
153-
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\"}"
156+
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\"}"
154157
```
155158

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

162+
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.
163+
159164
<img src="images/push-server-key.png" width="459px" height="220px" alt="Push server key"/>

firebase.ios.js

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ firebase.addAppDelegateMethods = function(appDelegate) {
101101
addBackgroundRemoteNotificationHandler(appDelegate);
102102
};
103103

104-
addBackgroundRemoteNotificationHandler(getAppDelegate());
105-
106104
firebase.addOnMessageReceivedCallback = function (callback) {
107105
return new Promise(function (resolve, reject) {
108106
try {
@@ -225,7 +223,7 @@ firebase._registerForRemoteNotifications = function () {
225223
}
226224
if (firebase._registerForRemoteNotificationsRanThisSession) {
227225
// ignore
228-
return;
226+
// return;
229227
}
230228
firebase._registerForRemoteNotificationsRanThisSession = true;
231229

@@ -289,6 +287,29 @@ firebase._registerForRemoteNotifications = function () {
289287
}
290288
};
291289

290+
function getAppDelegate() {
291+
// Play nice with other plugins by not completely ignoring anything already added to the appdelegate
292+
if (application.ios.delegate === undefined) {
293+
var __extends = this.__extends || function (d, b) {
294+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
295+
function __() { this.constructor = d; }
296+
__.prototype = b.prototype;
297+
d.prototype = new __();
298+
};
299+
300+
var appDelegate = (function (_super) {
301+
__extends(appDelegate, _super);
302+
function appDelegate() {
303+
_super.apply(this, arguments);
304+
}
305+
appDelegate.ObjCProtocols = [UIApplicationDelegate];
306+
return appDelegate;
307+
})(UIResponder);
308+
application.ios.delegate = appDelegate;
309+
}
310+
return application.ios.delegate;
311+
}
312+
292313
// rather than hijacking the appDelegate for these we'll be a good citizen and listen to the notifications
293314
function prepAppDelegate() {
294315
if (typeof(FIRMessaging) !== "undefined") {
@@ -328,29 +349,7 @@ function prepAppDelegate() {
328349
firebase.addAppDelegateMethods(getAppDelegate());
329350
}
330351

331-
function getAppDelegate() {
332-
// Play nice with other plugins by not completely ignoring anything already added to the appdelegate
333-
if (application.ios.delegate === undefined) {
334-
var __extends = this.__extends || function (d, b) {
335-
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
336-
function __() { this.constructor = d; }
337-
__.prototype = b.prototype;
338-
d.prototype = new __();
339-
};
340-
341-
var appDelegate = (function (_super) {
342-
__extends(appDelegate, _super);
343-
function appDelegate() {
344-
_super.apply(this, arguments);
345-
}
346-
firebase.addAppDelegateMethods(appDelegate);
347-
appDelegate.ObjCProtocols = [UIApplicationDelegate];
348-
return appDelegate;
349-
})(UIResponder);
350-
application.ios.delegate = appDelegate;
351-
}
352-
return application.ios.delegate;
353-
}
352+
prepAppDelegate();
354353

355354
firebase.toJsObject = function(objCObj) {
356355
if (objCObj === null || typeof objCObj != "object") {
@@ -423,8 +422,6 @@ firebase.init = function (arg) {
423422
function runInit() {
424423
arg = arg || {};
425424

426-
prepAppDelegate();
427-
428425
// this requires you to download GoogleService-Info.plist and
429426
// it to app/App_Resources/iOS/, see https://firebase.google.com/support/guides/firebase-ios
430427
FIRApp.configure();
@@ -496,9 +493,6 @@ firebase.init = function (arg) {
496493
resolve(firebase.instance);
497494
}
498495

499-
// wrapped in a timeout to play nice with nativescript-angular's appdelegate handling,
500-
// but reverted because of #272
501-
// setTimeout(runInit, 0);
502496
runInit();
503497
} catch (ex) {
504498
console.log("Error in firebase.init: " + ex);

package.json

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
{
22
"name": "nativescript-plugin-firebase",
3-
"version": "3.10.2",
3+
"version": "3.11.0",
44
"description": "Fire. Base. Firebase!",
55
"main": "firebase",
66
"typings": "index.d.ts",
77
"nativescript": {
88
"platforms": {
99
"android": "2.3.0",
1010
"ios": "2.3.0"
11-
}
11+
},
12+
"hooks": [
13+
{
14+
"type": "before-prepare",
15+
"script": "scripts/entitlements-before-prepare.js",
16+
"inject": true
17+
},
18+
{
19+
"type": "after-prepare",
20+
"script": "scripts/entitlements-after-prepare.js",
21+
"inject": true
22+
}
23+
]
1224
},
1325
"scripts": {
1426
"bundle-installer": "npm install --ignore-scripts && webpack --config scripts/webpack.config.js scripts/installer.js scripts/postinstall.js",
1527
"prepublish": "npm run bundle-installer",
16-
"postinstall": "node scripts/postinstall.js",
28+
"postinstall": "node postinstall-hooks.js && node scripts/postinstall.js",
29+
"preuninstall": "node preuninstall-hooks.js",
1730
"setup": "node scripts/postinstall.js setup",
1831
"config": "node scripts/postinstall.js config"
1932
},
@@ -48,7 +61,9 @@
4861
"homepage": "https://github.com/eddyverbruggen/nativescript-plugin-firebase",
4962
"dependencies": {
5063
"xcode": "0.8.0",
51-
"prompt-lite": "^0.1.1"
64+
"prompt-lite": "^0.1.1",
65+
"fs-promise": "^2.0.0",
66+
"nativescript-hook": "^0.2.1"
5267
},
5368
"devDependencies": {
5469
"prompt-lite": "^0.1.1",

postinstall-hooks.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('nativescript-hook')(__dirname).postinstall();

preuninstall-hooks.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('nativescript-hook')(__dirname).preuninstall();
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var fs = require('fs-extra');
2+
var path = require('path');
3+
4+
module.exports = function (logger, platformsData, projectData, hookArgs) {
5+
var platform = hookArgs.platform.toLowerCase(),
6+
appResourcesDirectoryPath = projectData.appResourcesDirectoryPath,
7+
entitlementsFile = path.join(appResourcesDirectoryPath, "iOS", projectData.projectName + ".entitlements"),
8+
projectRoot = path.join(projectData.platformsDir, "ios"),
9+
project = path.join(projectRoot, projectData.projectName);
10+
11+
return new Promise(function (resolve, reject) {
12+
if (platform == 'ios') {
13+
fs.exists(entitlementsFile, function (exists) {
14+
if (!exists) return reject(); //Error("entitlementsFile: `" + entitlementsFile + "` not found"));
15+
var dest = path.join(project, projectData.projectName + ".entitlements");
16+
fs.copy(entitlementsFile, dest, function (error) {
17+
if (error) return reject(error);
18+
resolve();
19+
});
20+
})
21+
} else {
22+
resolve();
23+
}
24+
});
25+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var fs = require('fs-extra');
2+
var path = require('path');
3+
4+
module.exports = function (logger, platformsData, projectData, hookArgs) {
5+
var platform = hookArgs.platform.toLowerCase(),
6+
appResourcesDirectoryPath = projectData.appResourcesDirectoryPath,
7+
platformResourcesDirectory = path.join(appResourcesDirectoryPath, 'iOS');
8+
9+
return new Promise(function (resolve, reject) {
10+
if (platform == 'ios') {
11+
var target = path.join(platformResourcesDirectory, 'build.xcconfig');
12+
13+
try {
14+
var buildData = fs.readFileSync(target).toString();
15+
if(!buildData.toString().match(/^\s*CODE_SIGN_ENTITLEMENTS/mg)){
16+
fs.appendFileSync(target, '\nCODE_SIGN_ENTITLEMENTS = ' + path.join(projectData.projectName, projectData.projectName + '.entitlements'));
17+
}
18+
} catch (error) {
19+
reject();
20+
}
21+
}
22+
23+
resolve();
24+
});
25+
};

0 commit comments

Comments
 (0)