我正在使用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>
但当然我得到一个白页,因为这段代码不打印任何东西。 如果我想将installid分配给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>
答案 0 :(得分:1)
您需要的是与设备相关的安装ID。您可能需要使用插件。
我使用的插件,按预期工作,可以找到here。
使用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');
});
}
答案 1 :(得分:0)
你应该使用插件,正如其他人所指出的,这是另一个执行相同工作的插件。 https://github.com/ccsoft/cordova-parse
PS:我是该插件的作者。