Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var user = $ionicUser.get();
- if(!user.user_id) {
- // Set your user_id here, or generate a random one.
- user.user_id = $ionicUser.generateGUID();
- };
- // Identify your user with the Ionic User Service
- $ionicUser.identify(user).then(function(){
- //$scope.identified = true;
- //alert('User ID ' + user.user_id);
- //alert("here");
- $ionicPush.register({
- canShowAlert: true, //Can pushes show an alert on your screen?
- canSetBadge: true, //Can pushes update app icon badges?
- canPlaySound: true, //Can notifications play a sound?
- canRunActionsOnWake: true, //Can run actions outside the app,
- onNotification: function(notification) {
- // Handle new push notifications here
- // console.log(notification);
- return true;
- }
- });
- });
- });
- })
- .config(['$ionicAppProvider', function($ionicAppProvider) {
- $ionicAppProvider.identify({
- app_id: 'xxxxxxxxxxxxx',
- api_key: 'xxxxxxxxxxxxxx',
- dev_push: false
- });
- }])
- $deviceToken = 'APA91bHKwBKrIjmmZ9lke97fl_GbOQ9iRRo-S2sNnZp085hPqVaTHMOd0wqhYFF1PtrtOzFrETX7ZNIkU0JDhC49Tby_AEFIQFRX99B0QpZd7xdiTqsP6sZ08P-8ESdJAie5AJNxhW89nQ7S9evZNcAc9tsJaG91Xw';
- $registrationIds = explode(",",$deviceToken);
- //$registrationIds = array($deviceToken);
- // prep the bundle
- $msg = array
- (
- 'notId' => time(),
- 'message' => 'Technovault is awesome!!!',
- 'title' => 'Title',
- 'smallIcon' =>'icon'
- );
- $fields = array
- (
- 'registration_ids' => $registrationIds,
- 'data' => $msg
- );
- $headers = array
- (
- 'Authorization: key=' . 'xxxxxxxxxx',
- 'Content-Type: application/json'
- );
- $ch = curl_init();
- curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
- curl_setopt( $ch,CURLOPT_POST, true );
- curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
- curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
- curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
- curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
- $result = curl_exec($ch );
- curl_close( $ch );
- echo $result;
- }
- else {
- echo "Error";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement