EExcel 丞燕快速查詢2

EExcel 丞燕快速查詢2
EExcel 丞燕快速查詢2 https://sandk.ffbizs.com/
顯示具有 FCM 標籤的文章。 顯示所有文章
顯示具有 FCM 標籤的文章。 顯示所有文章

ionic2 FCM send message to device token

1、ionic start sendnotify blank --v2

2、cordova plugin add cordova-plugin-whitelist

3、src/index.html
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-eval' 'unsafe-inline' *; object-src 'self'; style-src 'self' 'unsafe-inline'; media-src *">
4、ionic serve  

====if success=====

5、home.ts

add

import { Http, Headers, RequestOptions } from '@angular/http';
import 'rxjs/add/operator/map';

add   constructor(private http: Http


sendnotify_devicetoken(devictoken) {
      let url = 'https://fcm.googleapis.com/fcm/send';

      let headers = new Headers({ 
        'Content-Type': 'application/json',
        'Authorization': 'key=your key'
      });
      let options = new RequestOptions({ headers: headers });

      let body = {
        "notification":{
          "title":"Notification title",
          "body":"Notification body",
          "sound":"default",
          "click_action":"FCM_PLUGIN_ACTIVITY",
          "icon":"fcm_push_icon"
        },
        "data":{
          //"param1":"value1",
          //"param2":"value2"
        },
        //"to":"/topics/topicExample",
        "to": devictoken,
        "priority":"high",
        "restricted_package_name":""
      };


      this.http.post(url, body, options).map(
          (res) => {return res}//res.json()
      ).subscribe(
          data => {
            alert(data);
          },
          err => {
            alert("ERROR!: "+err);
          }
      );

a. devictoken: see http://sueboy.blogspot.tw/2017/01/ionic2-fcm-get-device-token.html

b. your key:firebase console -> project setting -> cloud messaging ->
have two new and old api key.   Use new is better

6、ionic serve  push button, then send success

ionic2 FCM get device token

https://github.com/fechanique/cordova-plugin-fcm

1、 ionic start getdevicetoken blank --v2

2、ionic plugin add cordova-plugin-fcm --save

3、 firebase console  -> project setting -> add your project

 a. package name: copy from config.xml id="com.ionicframework.getdevicetokenxxxxxx"

 b. add project then  download google-services.json

4、put google-services.json  on getdevicetoken directory,  don't put getdevicetoken/platforms/android or ..../ios

5、ionic run android  ( remeber open  android emule)

=====If success, contiune=====
6、src/pages/home

a.  home.html replace <ion-content
  <ion-list>
    <ion-item>
      <ion-textarea  rows="6" [value]="devicetoken"></ion-textarea>
    </ion-item>
    <button ion-button (click)="getdevicetoken()">
      getdevicetokens
    </button>
    <button ion-button (click)="showdevicetoken()">
      showdevicetoken
    </button>  
    <button ion-button (click)="Notification()">
      Notification
    </button>
 
  </ion-list>

b.  home.ts

  •  before @Component  put

declare var FCMPlugin;


  •  replace export class HomePage{

  devicetoken: string;

  constructor(public navCtrl: NavController) {
    FCMPlugin.onNotification((data) => {
      if(data.wasTapped){
        //Notification was received on device tray and tapped by the user.
        alert( JSON.stringify(data) );
      }else{
        //Notification was received in foreground. Maybe the user needs to be notified.
        alert( JSON.stringify(data) );
      }
    }, (msg) => {
      alert("notification msg:"+msg);
    }, (err) => {
      alert("notification err:"+err);
    });
  }

  getdevicetoken(){
    FCMPlugin.getToken((token) => {
        this.devicetoken = token;
    }, (err) => {
      alert("getdevicetoken err:"+err);
    });
  }

  showdevicetoken(){
    alert(this.devicetoken);
  }

  Notification(){
    
  }


7、save, ionic run android
a. getdevicetoken
b. showdevicetoken  then copy devicetoken

8、firebase console -> Notifications -> add send message ->
a. put message text
b. chosses deivce (single deivce) put devicetoken
c. send

9、receive msg on android emule: two way front、background receive~


ionic2 firebase FCM FCM_TOKEN Device_token Sender_id

https://forum.ionicframework.com/t/push-notifications-with-ionic-2/63851/4
https://github.com/fechanique/cordova-plugin-fcm
=====

https://www.youtube.com/watch?v=7yXtzhqT1uk
https://medium.com/@ankushaggarwal/push-notifications-in-ionic-2-658461108c59#.ff6hz41ot


.sender_id   who is sender or This guy is send message.

.FCM_token (api_key)  it's right to use FMC, who get token, then can send

.Device token  this device (which device)


Where is come from?

.sender_id 、 FCM_token from FCM (firebase)

.Device_token from device



How to get?

.sender_id 、 FCM_token : login firebase console -> settings -> colud messageing

.Device_token : If ionic2, when you use
Push @ionic/cloud-angular push.register().then(t: PushToken)
this time get Push Token. see video 7:54



So how to work?  (If see youtube video, I guess)

.FCM_token:   Who take token, who can send message. FCM get FCM_token, then send message to send_id  under all register.

.sender_id: App or reciver must have this info, when message come from FCM into Phone, then check send_id is correct or not.

.Device_token:
A、Device must send(register) phone's Device_toke to FCM sender_id, then register info(device_token) under send_id. If not register, send_id can't know any devices.

B、Sometime send message to only one device, must use FCM_token + Device_token then only send to one device.

(This Video 9:38 bottom have "Device Options")

(https://github.com/aggarwalankush/push-notification-server
AndroidPush.java  see code have "YOUR_DEVICE_TOKEN" )



https://medium.com/@ankushaggarwal/push-notifications-in-ionic-2-658461108c59#.ff6hz41ot
https://devdactic.com/ionic-push-notifications-guide/