2017-01-14 5 views
0

Мне нужно реализовать PushNotification для устройства iOS.Appcelerator Ti.Network.registerForPushNotifications события не срабатывают на iOS

Сообщение об ошибке это, когда я хочу подписаться на канал Отсутствующие поля. Обязательно: device_token и канал

У меня есть сертификат Apple и все конфигурации в панели инструментов Appcelerator.

И когда я запускаю приложение в своем приложении устройства, требуя подтверждения push-уведомления.

Я считаю, что ошибка возникает из-за событий Ti.Network.registerForPushNotifications, которые не срабатывают.

Вот мой код.

var Cloud = require("ti.cloud"); 

login(); 

function login() { 

env = Ti.App.deployType.toLowerCase() === 'production' ? 'production' : 'development', 
username = Ti.App.Properties.getString('acs-username-'+env), 
password = Ti.App.Properties.getString('acs-password-'+env); 

// Places your already created user id credential 
Cloud.Users.login({ 
    login : username, 
    password : password 
}, function(e) { 
    if (e.success) { 

     var user = e.users[0]; 
     Ti.API.info(' Login Success:\n' + 'id: ' + user.id + '\n' + 'sessionId: ' + Cloud.sessionId + '\n' + 'first name: ' + user.first_name + '\n' + 'last name: ' + user.last_name); 

    } else { 
     Ti.API.info('Error:\n' + ((e.error && e.message))); 
    } 
}); 

} 

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() { 

     Ti.App.iOS.removeEventListener('usernotificationsettings', registerForPush); 

     Ti.Network.registerForPushNotifications({ 
      success : deviceTokenSuccess, 
      error : deviceTokenError, 
      callback : receivePush 
     }); 
    }); 

    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 
    }); 
} 

function receivePush(e) { 
    //Ti.API.info('Received push: ' + JSON.stringify(e)); 
} 

function deviceTokenSuccess(e) { 
    deviceToken = e.deviceToken; 
    Ti.API.info("eeeeeeee" + e); 
    //subscribeToChannel(); 
} 

function deviceTokenError(e) { 
    Ti.API.info('ssssssssFailed to register for push notifications! ' + e.error); 
} 

function subscribeToChannel() { 
    // Subscribes the device to the 'news_alerts' channel 
    // Specify the push type as either 'android' for Android or 'ios' for iOS 

    Cloud.PushNotifications.subscribeToken({ 
     device_token: deviceToken, 
     channel: 'news_alerts', 
     type: Ti.Platform.name == 'android' ? 'android' : 'ios' 
    }, function (e) { 
     if (e.success) { 
      Ti.API.info('Subscribed'); 
     } else { 
      Ti.API.info('Error:\n' + ((e.error && e.message))); 
     } 
    }); 
} 

function unsubscribeToChannel() { 
    // Unsubscribes the device from the 'test' channel 
    Cloud.PushNotifications.unsubscribeToken({ 
     device_token: deviceToken, 
     channel: 'news_alerts', 
    }, function (e) { 
     if (e.success) { 
      Ti.API.info('Unsubscribed'); 
     } else { 
      Ti.API.info('Error:\n' + ((e.error && e.message))); 
     } 
    }); 
} 

setTimeout(function() { 
    subscribeToChannel(); 
    }, 6000); 
+0

Вы уверены, что вы получаете маркер устройства? А также убедитесь, что вы создали этот ** канал: «news_alerts» ** на панели приложений Appc, прежде чем регистрировать пользователей. –

ответ

0

Перед выполнением вызовов Стрелка DB, убедитесь, что ваш deviceTokenSuccessCB является уволят и так как вы показали, что это не уволят, то вы можете ниже шаги для этого:

  • Ваши настройки устройства IOS являются ON для уведомлений вашего приложения.
  • Вы не используете LiveView ON режима, как это известная проблема здесь LiveView ON iOS Notification issue
+0

Спасибо! LiveView - проблема в моем случае. – ggdev