Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS Appcelerator中获取设备令牌_Ios_Titanium_Appcelerator Studio - Fatal编程技术网

如何在iOS Appcelerator中获取设备令牌

如何在iOS Appcelerator中获取设备令牌,ios,titanium,appcelerator-studio,Ios,Titanium,Appcelerator Studio,我正在使用Appcelerator Studio 我想从iPhone获得设备令牌。我正在关注Appcelerator文档,但是当安装应用程序时,它会向我显示警报“DoyouwantReceiveNotification”,单击后控制台中不会打印任何内容 这是我的密码: var self = Titanium.UI.createWindow({ backgroundColor : '#146FA6', title : 'Menu', }); var deviceToken = nu

我正在使用Appcelerator Studio

我想从iPhone获得
设备令牌
。我正在关注Appcelerator文档,但是当安装应用程序时,它会向我显示警报“DoyouwantReceiveNotification”,单击后控制台中不会打印任何内容

这是我的密码:

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(".")[0]) >= 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 : [Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT, Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND, Ti.App.iOS.USER_NOTIFICATION_TYPE_BADGE]
    });
}

// For iOS 7 and earlier
else {
    Ti.Network.registerForPushNotifications({
        // Specifies which notifications to receive
        types : [Ti.Network.NOTIFICATION_TYPE_BADGE, Ti.Network.NOTIFICATION_TYPE_ALERT, Ti.Network.NOTIFICATION_TYPE_SOUND],
        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();

如果启用了LiveView,请禁用它

使用LiveView和推送通知服务时存在一些已知冲突

要使用Titanium Studio禁用LiveView功能,请查看Appcelerator Studio工具栏,如下所示


然后取消选择第一项。

代码应如下所示

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(".")[0]) >= 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: deviceTokenSuccess,
        error: deviceTokenError,
        callback: receivePush
    });
});

// Register notification types to use
Ti.App.iOS.registerUserNotificationSettings({
    types: [
        Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT,
        Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND,
        Ti.App.iOS.USER_NOTIFICATION_TYPE_BADGE
    ]
});
}

// For iOS 7 and earlier
else {
Ti.Network.registerForPushNotifications({
    // Specifies which notifications to receive
    types: [
        Ti.Network.NOTIFICATION_TYPE_BADGE,
        Ti.Network.NOTIFICATION_TYPE_ALERT,
        Ti.Network.NOTIFICATION_TYPE_SOUND
    ],
    success: deviceTokenSuccess,
    error: deviceTokenError,
    callback: receivePush
});
}
 // Process incoming push notifications
function receivePush(e) {
alert('Received push: ' + JSON.stringify(e));
}
// Save the device token for subsequent API calls
function deviceTokenSuccess(e) {
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);

}
function deviceTokenError(e) {
alert('Failed to register for push notifications! ' + e.error);
}
self.open();

你使用的是模拟器还是设备?我使用的是设备。iphone 5s操作系统(9.2.1)如何禁用ListView