【发布时间】:2014-08-12 09:53:54
【问题描述】:
我正在使用 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>
【问题讨论】:
标签: javascript ios cordova push-notification parse-platform