[TIMOB-26399] iOS: Several issues with push-notifications since 7.3.x
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-09-28T14:25:09.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 7.4.1 |
Components | iOS |
Labels | ios, parity |
Reporter | Greg |
Assignee | Hans Knöchel |
Created | 2018-09-19T17:18:50.000+0000 |
Updated | 2018-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)
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
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!
Added master PR :) - master: https://github.com/appcelerator/titanium_mobile/pull/10330 - 7_4_X: https://github.com/appcelerator/titanium_mobile/pull/10328
I have an issue when the app crashes on trying to register to push notification.Does this PR covers that case too ? Thank you.
[~rborn] you can try the latest 7.4.1 with
ti sdk install -b 7_4_X
![~hknoechel] same issue. 7.2.0 works just fine
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.
{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
is this from a local notification or a remote?
Remote
False alarm. The issue seems to be in the payload. Thanks Greg for your help!
It was not the payload. I had the Pushwoosh module being loaded in tiapp.xml , and it looks like it was swizzling the
from within the framework, and crashing when receiving unexpected data
[~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?
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.
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 2cAt 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.
Hmm - are you tapping a notification or a notification action?
notification
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.
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.
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
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:
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.
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.
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.
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
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.
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.
This commit: https://github.com/appcelerator/titanium_mobile/pull/10354/commits/5cf0b1c0a963929dfeea00fce530361baea28f21 Master PR: https://github.com/appcelerator/titanium_mobile/pull/10353
Backport 7.4.x https://github.com/appcelerator/titanium_mobile/pull/10355
Reopening to include one more fix to make notifications less error-prone.
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)
Verified changes included in SDK 7.4.1.v20180928073117 & 7.5.0.v20180928064200. Ran the Push Notification test apps and sample code without issue.