Skip to content

Instantly share code, notes, and snippets.

@komendantaa
Last active October 17, 2019 12:27
Show Gist options
  • Save komendantaa/d0e70584f47dc71b4f4856552435f5f3 to your computer and use it in GitHub Desktop.
Save komendantaa/d0e70584f47dc71b4f4856552435f5f3 to your computer and use it in GitHub Desktop.
Facebook manual
*docs
https://github.com/jeduan/cordova-plugin-facebook4
===== CREATE APP ======
https://developers.facebook.com
===== INSTALLATION =====
Install the Cordova and Ionic Native plugins:
$ ionic cordova plugin add cordova-plugin-facebook4 --variable APP_ID="123456789" --variable APP_NAME="myApplication"
$ npm install @ionic-native/facebook
*tested versions:
package.json
"@ionic-native/crop": "^4.16.0",
"@ionic-native/facebook": "^4.17.0",
"cordova-plugin-facebook4": {
"APP_ID": "APP_ID",
"APP_NAME": "APP_NAME",
"FACEBOOK_ANDROID_SDK_VERSION": "4.38.1"
},
//config.xml
<plugin name="cordova-plugin-facebook4" spec="^3.2.0">
<variable name="APP_ID" value="APP_ID" />
<variable name="APP_NAME" value="APP_NAME" />
<variable name="FACEBOOK_ANDROID_SDK_VERSION" value="4.38.1" />
</plugin>
*add to config.xml
<config-file parent="/resources" target="./res/values/strings.xml">
<string name="fb_app_id"> APP_ID </string>
<string name="fb_app_name"> APP_NAME </string>
</config-file>
=============
===== ANDROID (phonegap-plugin-push > 2.0) =====
insert google-services.json to platforms/android/app/
*generator
<platform name="android">
<resource-file src="google-services.json" target="app/google-services.json" />
*doc
https://developers.google.com/android/guides/google-services-plugin
* phonegap-plugin-push < 2.0
<plugin...
<variable name="SENDER_ID" value="{firebase settings>Cloud Messaging> SenderID}"/>
--- handle errors ---
"Execution failed for task ':app:processDebugGoogleServices'.
> Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 11.6.2."
- You must use only one version for all 3 libs in build.gradle
(for example "11.8.0" instead of "11.6.2"):
compile 'com.google.firebase:firebase-messaging:11.8.0'
compile 'com.google.android.gms:play-services-maps:11.8.0'
compile 'com.google.android.gms:play-services-location:11.8.0'
===========
===== IOS (continue install)=====
go through steps in facebook doc
1. on https://developer.apple.com/account/ios/identifier/bundle
- App IDs -> "appName" edit -> Push Notifications -> create production! SSL certificate
- Create a CSR file following instructions (create *.certSigningRequest)
- upload CSR (*.certSigningRequest)
- download SSL *.cer -> add to keychain on mac(2click)
2. on https://developer.apple.com/account/ios/certificate/distribution
- download iOS Distribution certificate *.cer
- add to keychain on mac(2click)
3. on https://developer.apple.com/account/ios/profile/
- Distribution Ad Hoc following instructions (Select certificate to include from step.2)
- download *.mobileprovision -> add to Xcode(2click)
4. in Xcode
- General -> Signing -> uncheck "Automatically manage signing"
- select created Provisioning profile(*.mobileprovision) for Signing(Debug)/(Release)
- Build Settings -> Code Signing Identify:
Debug/Release: iOS Developer
Any iOS SDK: certificate from step.2(identities in keychain)
5. in keychain (for tests)
- create *.p12 via exporting certificate(step.2) from keychain
--- handle errors ---
"ld: library not found for -lGoogleToolboxForMac"
first way:
clear Xcode product
$ cordova platform rm ios
$ cordova platform add ios
$ ionic cordova build ios
open xcproject then xcworkspace
second way:
go to platforms/ios
$ sudo gem install cocoapods
$ pod setup
============
===== IMPLEMENTATION =====
//app.module.ts:
import { Push } from '@ionic-native/push';
@NgModule({
...
providers: [..., Push]
...
})
// component.ts
import { Push, PushObject, PushOptions } from "@ionic-native/push";
constructor(
private push: Push,
//private authService: AuthorizeService,
) {
platform.ready().then(() => {
setTimeout(() => {
this.pushInit();
}, 2000);
});
}
presentToast(text) {
let toast = this.toastCtrl.create({
message: text,
duration: 2500,
position: 'top'
});
toast.present();
}
pushInit() {
this.push.hasPermission()
.then((res: any) => {
if (res.isEnabled) {
console.log('We have permission to send push notifications');
} else {
console.log('We do not have permission to send push notifications');
}
});
const options: PushOptions = {
android: {
//senderID: '87589863427',
sound: true,
vibrate: true,
icon: "icon",
iconColor: "#FFFFFF",
},
ios: {
alert: true,
badge: true,
sound: true,
clearBadge: true
},
windows: {},
browser: {
pushServiceURL: 'http://push.api.phonegap.com/v1/push'
}
};
const pushObject: PushObject = this.push.init(options);
pushObject.on('notification').subscribe((notification: any) => {
if(notification.additionalData.foreground) {
this.presentToast(notification.message);
}
});
pushObject.on('registration').subscribe((registration: any) => {
//this.authService.pushTokenUpdate(registration).subscribe(
//res => console.log(res),
//err => console.log(err));
console.log('Device registered', registration);
});
pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));
}
==============
====== TESTS ======
--- ANDROID ---
1. manually cloud Messaging in firebase
2. FCM (postman)
- method: "post"
- url: https://fcm.googleapis.com/fcm/send
- headers:
Content-Type , application/json
Authorization , key= firebase settings ->Cloud Messaging -> Legacy server key
- body:
{
"to": 'registrationId' from response pushObject.on('registration'),
"notification":{
"body":"test",
"title":"test",
"sound": "true"//default
},
"data":{}
}
--- IOS ---
Download https://github.com/noodlewerk/NWPusher
- import *.p12 from iOS step.5
- uncheck "Should use sandbox enviroment"
- insert device push token
- insert template:
{"aps":{"alert":"Testing.. (0)","sound":"default"}}
- init
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment