ios - 我们如何在 iOS Appcelerator 中获取设备 token
<p><p>我正在使用 Appcelerator Studio。 </p>
<p>我想从 iPhone 获取 <code>device token</code>。我正在关注 Appcelerator 文档,但是当应用程序安装时,它会向我显示警报“你想收到通知吗”,并且单击它后,控制台中不会打印任何内容。</p>
<p>这是我的代码:</p>
<pre><code>var self = Titanium.UI.createWindow({
backgroundColor : '#146FA6',
title : 'Menu',
});
var deviceToken = null;
// Check if the device is running iOS 8 or later
if (Ti.Platform.name == "iPhone OS" && parseInt(Ti.Platform.version.split(".")) >= 8) {
// Wait for user settings to be registered before registering for push notifications
Ti.App.iOS.addEventListener('usernotificationsettings', function registerForPush() {
// Remove event listener once registered for push notifications
Ti.App.iOS.removeEventListener('usernotificationsettings', registerForPush);
Ti.Network.registerForPushNotifications({
success : function(e) {
var deviceToken = e.deviceToken;
alert(e.deviceToken);
Ti.API.info("Push notification device token is: " + deviceToken);
Ti.API.info("Push notification types: " + Titanium.Network.remoteNotificationTypes);
Ti.API.info("Push notification enabled: " + Titanium.Network.remoteNotificationsEnabled);
},
error : deviceTokenError,
callback : receivePush
});
});
// Register notification types to use
Ti.App.iOS.registerUserNotificationSettings({
types :
});
}
// For iOS 7 and earlier
else {
Ti.Network.registerForPushNotifications({
// Specifies which notifications to receive
types : ,
success : function(e) {
var deviceToken = e.deviceToken;
alert(deviceToken);
Ti.API.info("Push notification device token is: " + deviceToken);
Ti.API.info("Push notification types: " + Titanium.Network.remoteNotificationTypes);
Ti.API.info("Push notification enabled: " + Titanium.Network.remoteNotificationsEnabled);
},
error : deviceTokenError,
callback : receivePush
});
}
//deviceTokenSuccess();
// Process incoming push notifications
function receivePush(e) {
alert('Received push: ' + JSON.stringify(e));
}
function deviceTokenError(e) {
alert('Failed to register for push notifications! ' + e.error);
}
self.open();
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>如果启用 LiveView,请将其禁用。 </p>
<p>在使用 LiveView 和推送通知服务时存在一些已知的冲突</p>
<p>要使用 Titanium Studio 禁用 LiveView 功能,请查看 Appcelerator Studio 工具栏,像这样</p>
<p> <a href="/image/Cl6mr.png" rel="noreferrer noopener nofollow"><img src="/image/Cl6mr.png" alt="enter image description here"/></a> </p>
<p>然后取消选择第一项。</p></p>
<p style="font-size: 20px;">关于ios - 我们如何在 iOS Appcelerator 中获取设备 token ,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/35146158/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/35146158/
</a>
</p>
页:
[1]