Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26399] iOS: Several issues with push-notifications since 7.3.x

GitHub Issuen/a
TypeImprovement
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2018-09-28T14:25:09.000+0000
Affected Version/sn/a
Fix Version/sRelease 7.4.1
ComponentsiOS
Labelsios, parity
ReporterGreg
AssigneeHans Knöchel
Created2018-09-19T17:18:50.000+0000
Updated2018-10-05T04:00:30.000+0000

Description

Push notification support in SDK 7.4.0 is broken (since 7.3.1 with the move to UNUserNotificationCenter delegate) and has a number of pre existing issues. - no callbacks occur for remote notifications (regression) - all incomming notifications fire a pop up notification when app is in foreground (regression) - notification actions do not fire when interacting with remote notifications (regression) - actions do not process in the background (pre-existing) - no user text input is passed in the callback (regression) - silent notifications fire on the dedicated silent event AND the normal (pre-existing) - app can crash if a custom sound is specified (also reported via AC-5901)

Comments

  1. Greg 2018-09-19

    I have been working with @hknoechel on these issues and prepared a PR for the 7.4.X branch which addresses all of the above
  2. Hans Knöchel 2018-09-19

    Thanks for this PR [~miniman42], huge work! I will take care of getting a test-plan ready for this and handle the remaining linting issues. Can you please do me a favor and also open a pull-request against master? This is the usual procedure - approving master first and merging to the backported branch afterwards. Thanks!
  3. Greg 2018-09-19

    Added master PR :) - master: https://github.com/appcelerator/titanium_mobile/pull/10330 - 7_4_X: https://github.com/appcelerator/titanium_mobile/pull/10328
  4. Dan Tamas 2018-09-20

    I have an issue when the app crashes on trying to register to push notification.Does this PR covers that case too ? Thank you.
  5. Hans Knöchel 2018-09-20

    [~rborn] you can try the latest 7.4.1 with ti sdk install -b 7_4_X !
  6. Dan Tamas 2018-09-20

    [~hknoechel] same issue. 7.2.0 works just fine
       
       [ERROR] Script Error {
       [ERROR]     column = 24;
       [ERROR]     line = 18;
       [ERROR]     message = "-[TiApp setRemoteNotificationDelegate:]: unrecognized selector sent to instance 0x103704770";
       [ERROR]     nativeStack = "3   CoreFoundation  0x000000018d7ed810 <redacted> + 1412\n4   CoreFoundation  0x000000018d7ef4bc _CF_forwarding_prep_0 + 92\n5   Motorsport 0x0000000102ea5890 Motorsport + 4266128\n6   CoreFoundation  0x000000018d7ef660 <redacted> + 144\n7   CoreFoundation  0x000000018d6cb980 <redacted> + 292\n8   Motorsport 0x0000000102ab8810 Motorsport + 149520\n9   Motorsport 0x0000000102ab6dd8 Motorsport + 142808\n10  JavaScriptCore  0x0000000194b15ddc <redacted> + 348\n11  JavaScriptCore  0x00000001952002b8 <redacted> + 352\n12  JavaScriptCore  0x0000000194aed120 <redacted> + 29952\n13  JavaScriptCore  0x0000000194aed134 <redacted> + 29972\n14  JavaScriptCore  0x0000000194aed134 <redacted> + 29972\n15  JavaScriptCore  0x0000000194aed134 <redacted> + 29972\n16  JavaScriptCore  0x0000000194ae5a1c <redacted> + 300\n17  JavaScriptCore  0x000000019515d3f0 <redacted> + 424\n18  JavaScriptCore  0x0000000195314068 _ZN3JSC12profiledCallEPNS_9ExecStateENS_15ProfilingReasonENS_7JSValueENS_8CallTypeERKNS_8CallDataES3_RKNS_7ArgListE + 172\n19  JavaScriptCore  0x0000000194b1b284 JSObjectCallAsFunction + 368";
       [ERROR]     sourceURL = "file:///var/containers/Bundle/Application/832BDBA5-DFB5-4C21-9B80-8722D40DFD5B/Motorsport.app/pushHelper.js";
       [ERROR]     stack = "    at [native code]\n    at registerForPush(/pushHelper.js:18:24)\n    at tryToRegister(/pushHelper.js:6:16)\n    at onClick(/alloy/controllers/popups/pushSubscriptionsPopupWindow.js:19:67)\n    at onClick(/alloy/controllers/popups/popupButton.js:16:31)";
       [ERROR] } 
       
  7. Richard Lustemberg 2018-09-20

    I've tried the merged code and found a problem I was also encountering when I was doing my own troubleshooting. When attempting to forward the delegate call from UNUserNotificationCenter to the application delegate, an invalid selector exceptios is thrown and the app quits. The pushnotification callbacks are executed, though.
       - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
       {
         // For backwards compatibility with iOS < 10, we do not show notifications in-app, but make it configurable
         BOOL showInForeground = [TiUtils boolValue:notification.request.content.userInfo[@"showInForeground"] def:NO];
         if (showInForeground) {
           completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionSound);
         } else {
        //next call causes the app to crash
           [self application:[UIApplication sharedApplication] didReceiveRemoteNotification:notification.request.content.userInfo];
           completionHandler(UNNotificationPresentationOptionNone);
         }
       }
       
    {noformat} [ERROR]  The application has crashed with an uncaught exception 'NSInvalidArgumentException'. [ERROR]  Reason: [ERROR]  -[NSNull intValue]: unrecognized selector sent to instance 0x1bf5019a0 [ERROR]  Stack trace: [ERROR]  0 CoreFoundation 0x000000018effbf10 + 252 [ERROR]  1 libobjc.A.dylib 0x000000018e1c9a40 objc_exception_throw + 56 [ERROR]  2 CoreFoundation 0x000000018ef13154 + 0 [ERROR]  3 CoreFoundation 0x000000018f001810 + 1412 [ERROR]  4 CoreFoundation 0x000000018f0034bc _CF_forwarding_prep_0 + 92 [ERROR]  5 iNZDR 0x00000001029e6c8c iNZDR + 3009676 [ERROR]  6 iNZDR 0x00000001029cd1bc iNZDR + 2904508 [ERROR]  7 iNZDR 0x00000001029bc6b0 iNZDR + 2836144 [ERROR]  8 iNZDR 0x00000001028a5cb8 iNZDR + 1694904 [ERROR]  9 iNZDR 0x00000001029b3920 iNZDR + 2799904 [ERROR]  10 UIKitCore 0x00000001bba15bb0 + 3176 [ERROR]  11 UIKitCore 0x00000001bc1e45a0 + 680 [ERROR]  12 UIKitCore 0x00000001bc1e42a8 + 432 [ERROR]  13 UIKitCore 0x00000001bc227844 + 220 [ERROR]  14 UIKitCore 0x00000001bc228334 _performActionsWithDelayForTransitionContext + 112 [ERROR]  15 UIKitCore 0x00000001bc2276fc + 248 [ERROR]  16 UIKitCore 0x00000001bc220a10 + 368 [ERROR]  17 UIKitCore 0x00000001bba2d940 + 468 [ERROR]  18 FrontBoardServices 0x0000000191a2c5a0 + 228 [ERROR]  19 libdispatch.dylib 0x000000018ea34484 + 16 [ERROR]  20 libdispatch.dylib 0x000000018e9d7e58 + 224 [ERROR]  21 FrontBoardServices 0x0000000191a6a640 + 40 [ERROR]  22 FrontBoardServices 0x0000000191a6a2cc + 416 [ERROR]  23 FrontBoardServices 0x0000000191a6a8e8 + 56 [ERROR]  24 CoreFoundation 0x000000018ef8a5b8 + 24 [ERROR]  25 CoreFoundation 0x000000018ef8a538 + 88 [ERROR]  26 CoreFoundation 0x000000018ef89e1c + 176 [ERROR]  27 CoreFoundation 0x000000018ef84ce8 + 1040 [ERROR]  28 CoreFoundation 0x000000018ef845b8 CFRunLoopRunSpecific + 436 [ERROR]  29 GraphicsServices 0x00000001911f8584 GSEventRunModal + 100 [ERROR]  30 UIKitCore 0x00000001bb9ff558 UIApplicationMain + 212 [ERROR]  31 iNZDR 0x000000010270d8b8 iNZDR + 22712 [ERROR]  32 libdyld.dylib 0x000000018ea44b94 + 4 {noformat}
  8. Greg 2018-09-20

    is this from a local notification or a remote?
  9. Richard Lustemberg 2018-09-20

    Remote
  10. Richard Lustemberg 2018-09-20

    False alarm. The issue seems to be in the payload. Thanks Greg for your help!
  11. Richard Lustemberg 2018-09-20

    It was not the payload. I had the Pushwoosh module being loaded in tiapp.xml , and it looks like it was swizzling the
     - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
    from within the framework, and crashing when receiving unexpected data
  12. Dan Tamas 2018-09-21

    [~rlustemberg] Thank you for your insights. In my case I use https://github.com/arleyandrada/PushClient [~hknoechel] could you have a look maybe to see what's changed since 7.2.0.GA which works? I think it crashes because of the change here: https://github.com/appcelerator/titanium_mobile/commit/62e42b5affb99be545e7b0f7d7d599f400fcf49a#diff-1a9ce8f0d125c49bb4d2b29bc9057f89L257 - maybe you could add an alias to that function or something so the not-updated modules not to crash?
  13. Hans Knöchel 2018-09-21

    Thanks for the insight! I'd prefer to update the module to keep the SDK more clean, is that okay for you? Happy to provide the PR for that asap.
  14. Dan Tamas 2018-09-21

    I think you just break all the modules that use setRemoteNotificationDelegate and won't be updated ever, not only the one I use. I suppose you are aware that many modules are not and won't be updated in the future so the (few) devs still using Titanium won't be able to update to the newer versions. just my 2c
  15. Andreas Pingas 2018-09-26

    At iOS SDK 7.4.1 notification do not work properly when the app is running on background. You get the notifcation but when you open it a black page appears instead of opening normally. When the app is not running and its the first time that you receive a notification and you open it, it works properly.
  16. Greg 2018-09-26

    Hmm - are you tapping a notification or a notification action?
  17. Andreas Pingas 2018-09-26

    notification
  18. Greg 2018-09-26

    Is this a local or a remote notification? I have tested locally and tapping remote notification with app running and not running is working fine for me. Please provide more details.
  19. Andreas Pingas 2018-09-26

    Its a remote notification. On SDK 7.4.0 , you always get a notification but when you open it doesnt take you anywhere. On SDK 7.4.1 you receive it and when you open it inside the app crashes or Opens a black screen.
        var deviceToken = null;
        
        Ti.App.iOS.registerUserNotificationSettings({
        	types: [
        		Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT,
         		Ti.App.iOS.USER_NOTIFICATION_TYPE_BADGE,
              	Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND
         	]
        });
        	
        Ti.App.iOS.addEventListener('usernotificationsettings', function registerForPush() {
        	
            Ti.App.iOS.removeEventListener('usernotificationsettings', registerForPush); 
         
            Ti.Network.registerForPushNotifications({
                success:function(e) {
        			
        		},
                error:function(e) {
        			
        		},
                callback:function(e) {
        	
        			if (e.inBackground == 1) {			
        						
        			}
        			else {
        				
        			}
        			
        		}
            });
                
        });
        
  20. Greg 2018-09-26

    I will take a look shortly, 7.4.0 doesn't actually do anything with the notification (ie no callback to the js handler), it simple presents the notification - this all changed in 7.3.1 with the new notification delegate in the SDK. 7.4.1 enables the callback to the JS to maintain parity with the existing behaviour in 7.3.0 and below. Is your app actually "running"?- i.e actually executing - in background mode, or is simply that it was launched and then backgrounded? when you tap the notification? Just want to understand what is going on for you. The only time I can get a black screen is if I tap a background mode notification action AND don’t call the completion handler when the background JS is finished. If you open the app within 30 secs of tapping it, the app will be black. if you wait 30 secs the app will be fine. This is because there is a protection in the SDK to ensure the completion handler is called before the background processing execution time limit runs out (~30secs) if a JS dev forgets to call it. Note: you need to have the correct background mode for this to be enabled
                        <key>UIBackgroundModes</key>
                        <array>
                            <string>remote-notification</string>
                        </array>
        
  21. Andreas Pingas 2018-09-27

    I once used notification action. I have removed it on SDK 7.4.0 as I was no longer using it. I have only left the following:
        <key>UIBackgroundModes</key>
        <array>
        <string>remote-notification</string>
        </array>
        
    At SDK 7.4.0 was working properly. However, on SDK 7.4.1 a blank screen appeared. I have then removed it from 7.4.1 and work properly. It remains as a bug in the following situations: callback of registerForPushNotifications 1) When the app is running then its OKAY 2) When the app is closed and opens for the first time its OKAY 3) When the app is open but you use another app, you receive the notification but callback DOES NOT WORK.
  22. Greg 2018-09-27

    Andreas, I'm not sure what you expect to happen, but in situation (3) the callback cannot occur as your app is not in the foreground and will always be sent to the notification center. The only way around this is to use silent pushes (setting content-available in the payload...), which, if you have the remote-notification background mode, will "wake" your app and trigger the "silent" event (e.g Ti.App.iOS.addEventListener('silentpush', onSilent) - just don't forget to call the background handler when your done or you'll get more black screens... (Ti.App.iOS.endBackgroundHandler(e.handlerId)). Please also note the silent push does not always get delivered instantly and is subject to the iOS's power mgmt and rate limiting. Previously there was a bug where silent pushes were delivered to the normal notification callback (in addition to the silent callback). This was incorrect behaviour and was fixed in this update.
  23. Andreas Pingas 2018-09-27

    Yes but when i have a notification in notification center and i open it, i callback should fire when the app was in background. Thats what happened before sdk 7.4.0. Now that does not happen as i describe it on the point 3) above 3) When the app is open but you use another app, you receive the notification but callback DOES NOT WORK. ... inBackground : Boolean Boolean indicating if notification was received while app was in background. This property became available in Titanium Mobile 3.1.0 for iOS.
  24. Richard Lustemberg 2018-09-27

    Andreas, As a workaround, you can listen on remotenotificationaction. That event is being fired after the app resumes when you click on the notification from the notification center
  25. Greg 2018-09-27

    Hi Andreas, so in (3) you are tapping the notification - that was not clear to me. Now I understand that you are indicating that the notification received while app is backgrounded and is subsequently tapped is not triggering the callback on resume of the app - I'll investigate. Thanks Richard for the workaround - that action handler should probably be sanitised to only callback when an action identifier is present.
  26. Greg 2018-09-27

    Hi again. I'm putting a PR together atm to trigger the remote notification callback as opposed to the remotenotificationaction callback for the case when the action provided is a UNNotificationDefaultActionIdentifier (this is the presented action now provided when a user taps a notification in iOS). This removes the need for Richards workaround and ensures the completion callback is called in an orderly manner.
  27. Greg 2018-09-27

    This commit: https://github.com/appcelerator/titanium_mobile/pull/10354/commits/5cf0b1c0a963929dfeea00fce530361baea28f21 Master PR: https://github.com/appcelerator/titanium_mobile/pull/10353
  28. Greg 2018-09-27

    Backport 7.4.x https://github.com/appcelerator/titanium_mobile/pull/10355
  29. Hans Knöchel 2018-09-27

    Reopening to include one more fix to make notifications less error-prone.
  30. Greg 2018-09-27

    Identified a bug in relation to ios11 category registration (using: Ti.App.iOS.createUserNotificationCategory) that causes Ti.App.iOS.registerUserNotificationSettings to fail if categories are provided. Fixed in the following PR's: https://github.com/appcelerator/titanium_mobile/pull/10356 (Master) https://github.com/appcelerator/titanium_mobile/pull/10357 (7_4_X)
  31. Eric Wieber 2018-09-28

    Verified changes included in SDK 7.4.1.v20180928073117 & 7.5.0.v20180928064200. Ran the Push Notification test apps and sample code without issue.

JSON Source