Skip to content

Instantly share code, notes, and snippets.

@janewang
Created May 12, 2015 17:14
Show Gist options
  • Save janewang/c9cbeb420e48272e4b8c to your computer and use it in GitHub Desktop.
Save janewang/c9cbeb420e48272e4b8c to your computer and use it in GitHub Desktop.
.controller('WelcomeCtrl', function ($scope, $state, $ionicPush, $cordovaPush, $ionicUser, $rootScope, $ionicHistory, $stateParams) {
$rootScope.$on('$cordovaPush:tokenReceived', function (event, data) {
console.log('Got token', data.token, data.platform);
});
//Basic registration
$scope.pushRegister = function () {
console.log('Registering...');
console.log('This has device Token! :', deviceToken);
$ionicPush.register({
canShowAlert: false,
onNotification: function (notification) {
// Called for each notification for custom handling
$scope.lastNotification = JSON.stringify(notification);
}
}).then(function (deviceToken) {
$scope.token = deviceToken;
});
}
$scope.identifyUser = function () {
console.log('Identifying user: ', $ionicUser, ' ,token: ', $scope.token);
console.log('This has device Token! :', deviceToken);
var user = $ionicUser.get();
if (!user.user_id) {
console.log('No user id, generating one');
// Set your user_id here, or generate a random one
user.user_id = $ionicUser.generateGUID()
};
angular.extend(user, {
name: 'Test User',
message: 'I come from planet Ion'
});
console.log('this is the user: ', user);
$ionicUser.identify(user);
}
$scope.login = function () {
$state.go('app.login');
}
$scope.signIn = function () {
$state.go('app.signIn');
}
if ($stateParams.clear) {
$ionicHistory.clearHistory();
$ionicHistory.clearCache();
}
if ($rootScope.isLoggedIn) {
$state.go('app.welcome');
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment