Last active
August 29, 2015 14:24
-
-
Save jbasinger/8533c6fe4417990af665 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('yourTotallyAwesomeApp') | |
.run(function($ionicPlatform, $ionicPush, $ionicUser) { | |
$ionicPlatform.ready(function() { | |
//A cheat check to make sure we're on a device | |
if(window.plugins){ | |
$ionicPush.register({ | |
canRunActionsOnWake: true, | |
onNotification: function(notification) { | |
if (notification.event){ | |
if(notification.event == "registered"){ | |
//Here you'll want to do something with notification.regid | |
//It's the deviceToken your server will use to tell Ionic | |
//whose device this is. | |
console.log(notification.regid); | |
} | |
if(notification.event == "message"){ | |
//Yes you need to access payload.payload. | |
//I tried changing it to something else server side | |
//and it didn't work. Sorry =( | |
console.log(notification.payload.payload); | |
if(notification.foreground){ | |
//This state happens when the notification comes in and the user | |
//is in the application. | |
console.log('Foreground Notification Received!'); | |
} else { | |
if(notification.coldstart){ | |
//This state happens when the notification is selected by the | |
//user but the app is not currently running. | |
console.log('User tapped notification while app was closed!'); | |
} else { | |
//This state happens when the notification is selected by the | |
//user but the app has been backgrounded. | |
console.log('User tapped notification while app was backgrounded!'); | |
} | |
} | |
} | |
} | |
} | |
}).then(function(deviceToken) { | |
var user = $ionicUser.get(); | |
if(!user.user_id) { | |
user.user_id = device.uuid; | |
}; | |
$ionicUser.identify(user); | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment