![](/img/trans.png)
[英]How to get Parse.com PUSH registration device token in Phonegap on iOS
[英]how to read device token (parse.com) with phonegap/javascript iOS
我正在使用Phonegap开发适用于iOS的应用程序,并且使用parse.com通过Xcode随附的iOS SDK进行推送通知。 在我的应用程序中,用户可以登录,我需要知道用户的设备令牌才能向其发送单次推送通知,我知道如何在登录期间随用户/密码一起发送设备令牌,但我不知道如何读取它,我不知道Phonegap是否可以直接使用它,或者我是否需要使用C读取它,然后使用一个变量传递给Javascript。
编辑:我正在尝试使用Malloc的解决方案,并且我有此问题。 我通过CLI安装了插件,但我不知道如何使用它。 我创建一个示例页面
<html>
<head>
</head>
<body>
<script type="text/javascript> parsePlugin.getInstallationId(function(id) { document.write(id); }, function(e) { alert('error'); });
</script>
</body>
</html>
但是我当然会得到一个白页,因为此代码不会打印任何内容。 如果我想将installationid分配给javascript变量,该怎么办? 谢谢
更新2
现在我的示例页面中有此代码
<html>
<head>
</head>
<body>
<script type="text/javascript">
var appId = p3Z10Nj2GdmfuxCX1a9liu5VlPadbvgW********;
var clientKey = lFRl93OEDM0bFTVOKaA1iIXV4vuWS3S9********;
//
parsePlugin.initialize(
appId,
clientKey,
function() {
// The parse plugin is initialized correctly, query the installation id
parsePlugin.getInstallationId(
function(id) {
// Installation id is correctly queried
console.log('The installation id is: '+id);
},
function(e) {
alert('An error has occured while querying the installation id of your device');
});
},
function(e) {
alert('An error has occured while initializing the parse plugin');
});
</script>
</body>
</html>
更新3
<html>
<head>
</head>
<body>
<script type="text/javascript">
$(window).load(function() {
var appId = p3Z10Nj2gm8siK;
var clientKey = lFRl93OEDM0bFTVOKaA1iIXV4vu;
//
parsePlugin.initialize(
appId,
clientKey,
function() {
// The parse plugin is initialized correctly, query the installation id
parsePlugin.getInstallationId(
function(id) {
// Installation id is correctly queried
console.log('The installation id is: '+id);
},
function(e) {
alert('An error has occured while querying the installation id of your device');
});
},
function(e) {
alert('An error has occured while initializing the parse plugin');
});
}
</script>
</body>
</html>
您需要的是与设备相关的安装ID。 您可能需要为此使用插件。
我使用过的插件可以正常工作,可以在这里找到。
使用CLI安装它之后,您只需调用parsePlugin.getInstallationId函数,该函数将返回设备的安装ID。
请记住,每个设备将获得一个安装ID,但这并不意味着您始终只有一个。 由于您可以在多个设备上运行该应用程序,因此每个应用程序都有其安装ID。
更新:
插件应在调用getInstallationId
之前初始化:
$(window).load(function() {
var appId = YOUR_APP_ID;
var clientKey = YOUR_KEY_CLIENT;
//
parsePlugin.initialize(
appId,
clientKey,
function() {
// The parse plugin is initialized correctly, query the installation id
parsePlugin.getInstallationId(
function(id) {
// Installation id is correctly queried
console.log('The installation id is: '+id);
},
function(e) {
alert('An error has occured while querying the installation id of your device');
});
},
function(e) {
alert('An error has occured while initializing the parse plugin');
});
}
您应该使用其他人指出的插件,这是另一个执行相同工作的插件。 https://github.com/ccsoft/cordova-parse
PS:我是该插件的作者。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.