Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-18282] iOS:Push notification callback is not working when app is being opened directly from app drawer.

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionInvalid
Resolution Date2019-12-10T20:55:42.000+0000
Affected Version/sRelease 3.4.1, Release 3.5.0
Fix Version/sn/a
ComponentsiOS
Labelsqe-3.5.0, supportTeam
ReporterMotiur Rahman
AssigneeVijay Singh
Created2014-12-22T11:02:53.000+0000
Updated2019-12-10T20:55:42.000+0000

Description

Hi, I am using the registerForPushNotifications in my app. I get a push notification properly. There are three situations: 1. App is already opened. 2. App is closed and I get a notification in Notification center. I open the app by clicking on notification. 3. App is closed and I get a notification in Notification center. In this case I don't click on the notification and open the app from the app drawer by clicking on the app icon. In the first two steps the callback function gets called, but in the third step, it is not being called.

Testing Environment:

Titanium SDK: 3.4.1 Titanium CLI: 3.4.1 iOS Version: 8.1 iPad 5G, ti.cloud: 3.2.7 OS X Version: 10.9.5, Appcelerator Studio: 3.4.1

Actual Result

callback is not working when the app is being opened directly.

Expected Result

callback will work when the app is being opened directly.

Test Case

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

var win = Ti.UI.createWindow({
	backgroundColor : 'white',
	layout : 'vertical',
	exitOnClose : true
});

var subscribeBtn = Ti.UI.createButton({
	title : 'Subscribe',
	top : 50,
});
subscribeBtn.addEventListener('click', function() {
	loginUser();
});

function loginUser() {
	// Log in to ACS
	Cloud.Users.login({
		login : 'userName',
		password : 'PASS'
	}, function(e) {
		if (e.success) {
			alert('Login successful');
			subscribeToChannel();
		} else {
			alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e)));
		}
	});
}

//Retrive Device token

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) {
	function registerForPush() {
		Ti.Network.registerForPushNotifications({
			success : deviceTokenSuccess,
			error : deviceTokenError,
			callback : receivePush
		});
		// Remove event listener once registered for push notifications
		Ti.App.iOS.removeEventListener('usernotificationsettings', registerForPush);
	};

	// Wait for user settings to be registered before registering for push notifications
	Ti.App.iOS.addEventListener('usernotificationsettings', registerForPush);

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

} else {
	// For iOS 7 and earlier
	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;
}

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

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

win.add(subscribeBtn);
win.open();

Thanks.

Comments

  1. Wilson Luu 2014-12-29

    Was able to reproduce this issue in both SDK 3.4.1.GA and 3.5.0. Tested on: Appcelerator Studio, build: 3.4.1.201410281743 SDK build: 3.4.1.GA, 3.5.0.v20141222103320 CLI: 3.4.1 Alloy: 1.5.1 Xcode: 6.2 beta 3 Devices: iphone 6 plus (8.1.1)
  2. Motiur Rahman 2018-09-07

    It still an issue with the latest Ti SDK 7.3.1.GA Tested on: Appcelerator Command-Line Interface, version 7.0.6 Operating System Name = Mac OS X Version = 10.13.6 Node.js Node.js Version = 8.10.0 npm Version = 5.8.0 Titanium CLI CLI Version = 5.1.1 Titanium SDK SDK Version = 7.3.1.GA Device = iphone 5s (11.4.1) ti.cloud version = 3.2.111 Xcode: 9.4.1
  3. Motiur Rahman 2018-10-09

    Another issue with the latest Ti SDK version, if I press the home button for closing or backgrounding the App then send a push notification, the callback function is not firing. *Testing Environment:* Ti SDK v7.4.0.GA Xcode v10 Device? iPhone 5s v iOS12 *Steps To Reproduce:* 1. Create a new push App and configure it. 2. Send push notification and open the App from the push notification center, in this case, the callback function is firing. 3. Now press the HOME button and send the push notification again and open the App from the push notification center, in this case, the callback function is not working. This is the issue. Let us know if it's an issue or default behavior. Sample code: https://github.com/oneilmarcelo/pushnotification-appcelerator-ios/tree/master/net.chleba.pushnotificationios/app Thanks!
  4. Vijay Singh 2018-10-09

    [~morahman] In 7.4.1 there are many notification related issues has been fixed TIMOB-26399 and TIMOB-26444. Can you once check the behaviour using 7.4.1 SDK. You can get SDK via CLI - appc ti sdk install -b 7_4_X Thanks!
  5. Motiur Rahman 2018-10-16

    [~vijaysingh], My commented issue has been fixed with the latest Ti SDK 7.4.1 but still is an issue with the described issue. Thanks!
  6. Vijay Singh 2018-10-17

    [~morahman] What do you mean by "but still is an issue with the described issue"? Which issue is still there?
  7. Motiur Rahman 2018-10-18

    [~vijaysingh], Please look at the description box for that issue. "Push notification callback is not working when app is being opened directly from app drawer". Not sure it's an issue or normal behavior. Thanks!

JSON Source