Skip to content

Instantly share code, notes, and snippets.

@evantahler
Created June 1, 2012 12:31
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save evantahler/2851808 to your computer and use it in GitHub Desktop.
Save evantahler/2851808 to your computer and use it in GitHub Desktop.
PhoneGap / Cordova Device Token plugin JS component (iOs)
// An example of how to use the PhoneGap / Cordova plugin described in this post [[ http://blog.evantahler.com/phonegap-and-push-notifications ]] to get an iOs device token
document.addEventListener("deviceready", function(){
getDeviceToken();
}
getDeviceToken = function(){
if(typeof device != "undefined" && typeof cordova == "object"){
var getToken = function(types, success, fail){
cordova.exec(success, fail, "PushToken", "getToken", types);
}
getToken(["getToken"], function(token){
device.token = token;
return token;
}, function(e){
console.log("cannot get device token: "+e);
return false;
});
}else{
// console.log("device not ready, or not a native app");
return false;
}
}
getLastPushMessage = function(){
if(typeof device != "undefined" && typeof cordova == "object"){
var getMessageFromIos = function(types, success, fail){
cordova.exec(success, fail, "LastPushMessage", "getLastPushMessage", types);
}
getMessageFromIos(["getLastPushMessage"], function(message){
message = unescape(message);
return message;
}, function(e){
console.log("cannot get last message: "+e);
return false;
});
}else{
// console.log("device not ready, or not a native app");
return false;
}
}
@abhichand
Copy link

good article, can please help me in implementing this code. i want small code in html5 that can be converted into ios native app via phonegap and further use to get device tokens for iphone device for push notifications

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment