Google Cloud Messaging

Fuse version 1.2.1 (build 13974)
macOS Sierra version 10.12.6

/** Steps **/
1- uno clean.
2- fuse build --target=iOS --configuration=Release
3- opening the app with Xcode version 9.0 (9A235)
4-Building the app on iOS for both debugging or release.

/** Code **/

/*
**project.unoproj
*/

{
“RootNamespace”:"",
“Packages”: [
“Fuse”,
“FuseJS”,
“Fuse.GeoLocation”,
“Fuse.Camera”,
“Fuse.CameraRoll”,
“Fuse.ImageTools”,
“Fuse.PushNotifications”,
“Fuse.Launcher”
],
“Includes”: [
",
"API/
.js:Bundle”,
“Auth/*.js:Bundle”,
“socket.io-1.4.5.js:Bundle”,
“Assets/wanderlust-logo.png:Bundle”,
“GoogleService-Info.plist:ObjCSource:iOS”
],
“Title”: “Wanderlust”,
“Firebase”: {
“GoogleServices”: {
“iOS”: “GoogleService-Info.plist”
}
},
“Android”: {
“Package”:“com.apps.wanderlustfuse”,
“GooglePlay”: {
“SenderID”: “108807926978”
}
},
“iOS”: {
“BundleIdentifier”:“com.apps.wanderlustfuse”,
}
}

/*
**Notifications.js
*/
var push = require(“FuseJS/Push”);
var fcm_api = require("…/API/fcm");

push.on(“registrationSucceeded”, function(regID) {
console.log("Reg Succeeded: " + regID);
fcm_api.saveFcm(regID).then(function(response) {});
});

push.on(“error”, function(reason) {
console.log("Reg Failed: " + reason);
});

push.on(“receivedMessage”, function(payload) {
console.log("Recieved Push Notification: " + payload);
});

/*
**The Issue
*/
GCM Token never register or show an error while the same code is functioning just fine on android.

Hi Karim, GCM now requires a little tweak in iOS. We need to create the FCM token from iOS APNs token.

Here is the snippet using just Javascript:

Push.on("registrationSucceeded", function(regID) {
    if (Environment.ios) // "FuseJS/Environment' 
        APNStoFCM(regID);
});

function APNStoFCM(token) {
    console.log("transforming to FCM");
    var body = {
        application: 'your.package.name',
        sandbox: true,
        apns_tokens: [
            token
        ]
    };

    var options = {
        method: "POST",
        headers: {
            'Accept': 'application/json',
            "Content-type": "application/json; charset=UTF-8",
            'Authorization': 'key=your_key'
        },
        body: JSON.stringify(body)
    }

    fetch("https://iid.googleapis.com/iid/v1:batchImport", options)
        .then(function(response) {
	        console.log("Response " + JSON.stringify(response))
            return response.json();
        }).then(function(response) {
            console.log("Key " + JSON.stringify(response))
        }).catch(function(error) {
            console.log("Error " + JSON.stringify(error))
        });
}

This script it’s used here :slight_smile: Fuse-Firebase-Notifications

Another approach with FCM and more features of Firebase it’s here: Fuse.Firebase