Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-18390

iOS: App crashes after receiving some push notifications in background

    Details

    • Type: Bug
    • Status: Closed
    • Priority: High
    • Resolution: Invalid
    • Affects Version/s: Release 3.4.1, Release 3.5.0
    • Fix Version/s: None
    • Component/s: iOS
    • Environment:

      iOS, iPhone 5, iPhone 5s, iPhone6, iPhone 6 Plus
      iPhone 6 on iOS 8.1.1 and 8.1.2
      iPhone 6+ on iOS 8.0.2
      iPhone 5 on 8.1
      Mobile SDK 3.5.0 and 3.4.1

    • Story Points:
      5
    • Sprint:
      2015 Sprint 06 SDK

      Description

      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.

      Steps to reproduce

      1. Create a new mobile project
      2. Add this code to the app via app.js

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

      3. Please replace the ACS keys with your own and the GUID with your own.
      4. Install to device

      ti build -p ios -T device

      5. Open App
      Allow it to retrieve a device token (used below)
      6. Send 2 notifications

      for i in `seq 1 2`; do curl -X POST -F "channel=testChannel" -F "to_tokens=<DEVICE TOKEN>" -F "payload=$i" "https://api.cloud.appcelerator.com/v1/push_notification/notify_tokens.json?key=<YOUR ACS KEY>&pretty_json=true";done

      7. You'll see "CALLBACK..." in console logs
      8. Background app with home button
      9. Send 3+ noticiations

      for i in `seq 1 3`; do curl -X POST -F "channel=testChannel" -F "to_tokens=<DEVICE TOKEN>" -F "payload=$i" "https://api.cloud.appcelerator.com/v1/push_notification/notify_tokens.json?key=<ACS KEY>&pretty_json=true";done

      10. You should now get the crash in the console

      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.

        Attachments

        1. crash_log.txt
          2 kB
          Seth Toda

          Activity

            People

            • Assignee:
              emerriman Eric Merriman
              Reporter:
              VanCoding Patrik Stutz
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-19608
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Integration