Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17640] iOS8: Add isRegisteredForRemoteNotifications to determine whether the app is currently registered for remote notifications.

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-09-15T16:11:37.000+0000
Affected Version/sn/a
Fix Version/sRelease 3.4.0, Release 3.5.0
ComponentsiOS
Labelsios8
ReporterBen Bahrenburg
AssigneeJon Alter
Created2014-09-03T23:34:06.000+0000
Updated2014-11-21T20:30:20.000+0000

Description

Returns a Boolean indicating whether the app is currently registered for remote notifications. Add support for isRegisteredForRemoteNotifications so that the developer can check if the user has authorized notifications.
var hasAuthorized = Ti.App.iOS.isRegisteredForRemoteNotifications();
if(hasAuthorized) {
	Ti.API.info("User has already authorized");
} else {
	Ti.API.info("User needs to authorize, maybe ask them before the iOS rights dialog pops up");
}

Comments

  1. Ben Bahrenburg 2014-09-04

    Added pull request https://github.com/appcelerator/titanium_mobile/pull/6018 Ingo mentioned AppC is now taking iOS8 PR. This ticket was created in associated with PR 6018.
  2. Ingo Muschenetz 2014-09-04

    [~mpmiranda], for iOS 8 tickets, add a label of "ios8" and make sure the summary _starts_ with iOS8 (no spaces)
  3. Ingo Muschenetz 2014-09-08

    Jon, could you please take a look?
  4. Jon Alter 2014-09-10

    PR master: https://github.com/appcelerator/titanium_mobile/pull/6046 PR 3_4_X: https://github.com/appcelerator/titanium_mobile/pull/6047 This ticket will resolve TIMOB-17647 please resolve it when these PRs are merged.

    Test Code:

       
       var rows = [
       	{
       		title: 'remoteNotificationsEnabled',
       		onClick: function(){
       			logInApp("remoteNotificationsEnabled: " + Ti.Network.remoteNotificationsEnabled);
       		}
       	},
       	{
       		title: 'remoteNotificationTypes',
       		onClick: function(){
       			logInApp('remoteNotificationTypes: ' + JSON.stringify(Ti.Network.remoteNotificationTypes));
       		}
       	},
       	{
       		title: 'currentUserNotificationSettings',
       		onClick: function(){
       			// iOS 8 +
       			var settings =  Ti.App.iOS.currentUserNotificationSettings;
       			logUserNotificationSettings(settings);
       		}
       	},
       	{
       		title: 'registerUserNotificationSettings',
       		onClick: function(){
       			// iOS 8 +
       			// The following action launches the application in the foreground and requires the device to be unlocked
       			var acceptAction = Ti.App.iOS.createUserNotificationAction({
       			    identifier: "ACCEPT_IDENTIFIER",
       			    title: "Accept",
       			    activationMode: Ti.App.iOS.USER_NOTIFICATION_ACTIVATION_MODE_FOREGROUND,
       			    destructive: false,
       			    authenticationRequired: true
       			});
       
       			var foregroundCategory = Ti.App.iOS.createUserNotificationCategory({
       				identifier: "FOREGROUND_CATEGORY",
       			    // The following actions will be displayed for an alert dialog
       				actionsForDefaultContext: [acceptAction],
       			    // The following actions will be displayed for all other notifications
       				actionsForMinimalContext: [acceptAction]
       			});
       
       			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],
       	    		categories: [foregroundCategory]
       			});
       		}
       	},
       	{
       		title: 'registerForPushNotifications',
       		onClick: function(){
       			Ti.Network.registerForPushNotifications({
       				success: function(e) {logInApp('success');},
       				error: function(e) {logInApp('error');},
       				callback: function(e) {logInApp('callback');}
       			});
       		}
       	},
       	{
       		title: 'unregisterForPushNotifications',
       		onClick: function(){
       			Ti.Network.unregisterForPushNotifications();
       		}
       	},
       	{
       		title: 'scheduleLocalNotification',
       		onClick: function(){
       			Ti.App.iOS.scheduleLocalNotification({
       			    date: new Date(new Date().getTime() + 3000),
       			    alertBody: "New content available! Download now?",
       			    badge: 1,
       			    userInfo: {"url": "http://www.download.com/resource/asset.json"},
       			    category: "FOREGROUND_CATEGORY"
       			});
       		}
       	}
       ];
       
       function logInApp(text) {
       	textLog.value = textLog.value + '\n' + text;
       }
       
       function logUserNotificationSettings(settings) {
       	logInApp('UserNotificationSettings: ');
       	logInApp('types: ' + JSON.stringify(settings.types));
       	var categories = [];
       	for (var i = 0, j = settings.categories.length; i < j; i++) {
       		categories.push(settings.categories[i].identifier);
       	}
       	logInApp('categories: ' + JSON.stringify(categories));
       }
       
       Ti.App.iOS.addEventListener('usernotificationsettings', function(e) {
       	logInApp('Event: usernotificationsettings');
       	logUserNotificationSettings(e);
       });
       
       ////////////////////////////////////////////////////////
       // UI
       ////////////////////////////////////////////////////////
       var win = Ti.UI.createWindow({
       	backgroundColor: 'white'
       });
       win.open();
       
       var textLog = Ti.UI.createTextArea({
       	top: 0,
       	height: '20%',
       	width: '100%',
       	borderWidth: '2',
       	borderColor: '#000',
       	value: 'AppLog: see device log for more info'
       });
       win.add(textLog);
       
       var tableView = Ti.UI.createTableView({
       	top: '20%',
       	data: rows
       });
       tableView.addEventListener('click', function(e){
       	e.source.onClick && e.source.onClick();
       });
       win.add(tableView);
       
  5. Ingo Muschenetz 2014-09-11

    All, please see TIMOB-17683 as well. Thoughts appreciated.
  6. Vishal Duggal 2014-09-12

    PR's merged
  7. Wilson Luu 2014-09-16

JSON Source