Created
June 1, 2012 12:31
-
-
Save evantahler/2851808 to your computer and use it in GitHub Desktop.
PhoneGap / Cordova Device Token plugin JS component (iOs)
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
// 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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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