Project: titanium
Issue TIMOB-18390: iOS: App crashes after receiving some push notifications in background
h4. Problem Description I've discovered a bug where the app crashes when it receives some (3+) push notifications while the iPhone's screen is turned off and the app is in background. h4. Steps to reproduce 1. Create a new mobile project 2. Add this code to the app via app.js {code} var win = Ti.UI.createWindow({backgroundColor:"green"}); win.open(); var callbacks = { types: [ Titanium.Network.NOTIFICATION_TYPE_BADGE, Titanium.Network.NOTIFICATION_TYPE_SOUND, Titanium.Network.NOTIFICATION_TYPE_ALERT ], success:function(e){ console.log("SUCCESS",e.deviceToken); subscribeACS(e.deviceToken); }, error:function(e){ console.log("ERROR",new Date().toTimeString()); }, callback: function(e){ console.log("CALLBACK",new Date().toTimeString()); } }; if(Ti.App.iOS.registerUserNotificationSettings){ function onUserNotificationSettings(){ delete callbacks.types; Ti.Network.registerForPushNotifications(callbacks); Ti.App.iOS.removeEventListener("usernotificationsettings",onUserNotificationSettings); } Ti.App.iOS.addEventListener("usernotificationsettings",onUserNotificationSettings) Ti.App.iOS.registerUserNotificationSettings(callbacks) }else{ Ti.Network.registerForPushNotifications(callbacks) } function subscribeACS(token){	var Cloud = require('ti.cloud');	Cloud.PushNotifications.subscribeToken({	channel: 'testChannel',	device_token: token	}, function (e) {	if (e.success) {	alert('Success');	} else {	alert('Error:\n' +	((e.error && e.message) || JSON.stringify(e)));	}	}); } {code} 3. Please replace the ACS keys with your own and the GUID with your own. 4. Install to device {code}ti build -p ios -T device{code} 5. Open App Allow it to retrieve a device token (used below) 6. Send 2 notifications {code}for i in `seq 1 2`; do curl -X POST -F "channel=testChannel" -F "to_tokens=" -F "payload=$i" "https://api.cloud.appcelerator.com/v1/push_notification/notify_tokens.json?key=&pretty_json=true";done{code} 7. You'll see "CALLBACK..." in console logs 8. Background app with home button 9. Send 3+ noticiations {code}for i in `seq 1 3`; do curl -X POST -F "channel=testChannel" -F "to_tokens=" -F "payload=$i" "https://api.cloud.appcelerator.com/v1/push_notification/notify_tokens.json?key=&pretty_json=true";done{code} 10. You should now get the crash in the console h4. Extra information After some push notifications, the 'callback' function does not get called anymore. After that, when I turn the screen back on, the app crashes completely with an error in the console. This happens on at least iPhone 5S, iPhone 6 and iPhone 6 Plus and is a critical bug since it prevents users from receiving important notifications! I've put together an example app & server and closely documented this issue at: https://github.com/VanCoding/iOS-Push-Bug Using this you can reproduce this error on your own. I'm using SDK 3.4.0.GA btw.
Story points: 5