Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Silent notifications #1351

Closed
1 task done
raphaels17 opened this issue Dec 31, 2023 · 23 comments
Closed
1 task done

[Bug]: Silent notifications #1351

raphaels17 opened this issue Dec 31, 2023 · 23 comments

Comments

@raphaels17
Copy link

raphaels17 commented Dec 31, 2023

What happened?

I am on OneSignal 5.0.5 , iOS17.2 Xcode 15 now and followed documentation for UNNotificationServiceExtension, since I dont get how to get silent notification in any context ( foreground / background)

On the opposite if it work if the notification has a context .

I Have tested on both simulator and real devices with that example :

Can anyone help ?

Steps to reproduce?

Instal Framework v5 and NSE as per onesignal documentation .
Run your app on a device and start testing push notification 


`curl -X POST   -H "Content-Type: application/json"   -H "Authorization: Basic correct bearer"   -d '{
    "app_id": "dba7a98f-XXX-xxx-xxx-XXXX",
    "include_player_ids": ["5a02c072-da64-407f-XXXX"],
    "content_available": 1,
    "data": {"notificationType": "PartnerUpdated"}
  }'   https://onesignal.com/api/v1/notifications`

answer being : `{"id":"b0fca423-6158-4348-a934-3dd1c01d93bb","external_id":null}`

and yet nothing happens on my app Even when the app is on screen.  I never get to hit : 
`func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        NSLog("Were are going in \(String(describing: userInfo))")
        debugPrint("Were are going in \(String(describing: userInfo))")
        
        DispatchQueue.main.async {
                // Log or print messages here
                print("Received silent notification: \(userInfo)")
            }
        completionHandler(.newData)
    }`
If i set a message like so : 

`curl -X POST   -H "Content-Type: application/json"   -H "Authorization: Basic correctBearer"   -d '{                                                                 "app_id": "xxxx-037e-4b94-86b1-xxxxx",
    "include_player_ids": ["c6748265-XXX"],
    "content_available": 1,
    "data": {"setUserLastName": "My new Lastname"}
  }'   https://onesignal.com/api/v1/notifications`
    
    
it woks like a charm and func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) gets hit .

Note : everything worked prior I was v.2 and had no NSE.

What did you expect to happen?

I'd expect func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) to get hit and be able to process silent notifications

OneSignal iOS SDK version

5.0

iOS version

15

Specific iOS version

iOS 15.2
iOS 17.1

Relevant log output

none that is the issue

Code of Conduct

  • I agree to follow this project's Code of Conduct
@raphaels17 raphaels17 changed the title [Bug]: [Bug]: Silent notifications Jan 3, 2024
@emawby
Copy link
Contributor

emawby commented Jan 3, 2024

@raphaels17 Thank you for reporting. When the device is open and the notification is sent do you see any logs from OneSignal when verbose logging is enabled? If so could you share those logs in order to help us fix this issue? Additionally you could try debugging the Notification Service Extension target or looking at logs from that target.

If the NSE is never hit/you don't see any logs then the notification isn't making it to the app. If the NSE is hit and you do see logs then the notification is being received by the device, but the SDK is not forwarding it properly.

@binodav
Copy link

binodav commented Jan 8, 2024

I encountered the same issue. It suddenly stopped working since I upgraded to v5.0. The normal push notifications still works for me. But silent notification with content_available no longer works. Tested with FCM and even directly with APNS server, both methods are working for me. Currently I temporarily migrated all silent notifications to use APNS server.

@raphaels17
Copy link
Author

raphaels17 commented Jan 8, 2024

the NSE is never hit/ I don't see any logs for silent notifications.
I have tried both and even open a TSI with Apple, but as you mention, going to APNS seems to work they just don't do through NSE, so my guess is that the issue is with was it sent out by Onesignal, and NSE.

I we will start working on migrating our app to go via APNS first, this is way too critical.
I will provide you witht the verbose for none silent notifications on Thursday ( that works)

@elemans
Copy link

elemans commented Jan 12, 2024

I have the same problem since mid December last year: silent notifications via OneSignal stopped working without any change at my side. Only non-silent notifications work. I already had an endless but slow interaction with OneSignal support, but it seems that they can't reproduce the problem at their side. Perhaps a part of their servers are using incorrect code. I'm currently also switching to directly sending notifications requests to APNS.

@raphaels17
Copy link
Author

My guess is that the issue lies with how NSE is being handled cause our user base have different version of the framework and only those on 5 have the issue.
I think there are important misses in the procedure to set setup NSE for it to work. I had been on a sick leave so i couldn't provide them with the logs, but i getting to it this week.

@emawby
Copy link
Contributor

emawby commented Jan 16, 2024

This is not an issue with the NSE since I don't believe that the NSE should ever be notified of "content available" notifications, but I am able to reproduce the problem and am investigating.

@emawby
Copy link
Contributor

emawby commented Jan 16, 2024

@raphaels17 In your original post you mention that the second curl request worked and the first one didn't. Could you clarify what exactly you changed to make the request work for you?

@avargaskun
Copy link

avargaskun commented Jan 17, 2024

Fwiw I am seeing same problem on SDK v5 but was reproducible on v3 as well.

I have a handler for didReceiveRemoteNotification:fetchCompletionHandler on my AppDelegate. When sending silent notifications with content_available=1 via the OneSignal REST API, the remote notification handler does not get invoked. It does not matter if the app is in the foreground or background, the behavior is the same. Regular (visual) notifications work just fine.

When sending a background notification to the same client via the Apple's Push Notification Console, the remote notification handler is invoked. Which leads me to believe the issue may be between OneSignal and APNS. Perhaps a missing/incorrect header value? Is OneSignal sending the headers apns-push-type:background and apns-priority:5 on these background notifications?

@elemans
Copy link

elemans commented Jan 17, 2024

@avargaskun Exactly! Additional question: Is OneSignal sending the correct headers for background notifications on all their servers? It seems that since mid December last year, at least a part of OneSignal servers stopped using the correct implementation for background notifications for APNS.

@bendodson
Copy link

Just to add that I'm experiencing the same issues; silent notifications stopped working in December with zero code changes using iOS SDK 3.12.5. I've migrated to SDK 5.1.0 and am still seeing the same issue. Regular notifications are firing fine but any with content_available are not triggering the usual didReceiveRemoteNotification:fetchCompletionHandler in either foreground or background.

@alighani-zoral
Copy link

I am also experiencing the same behaviour. Silent Notifications are not being received from OneSignal since December.
@raphaels17 Why is the second curl working for you. Does changing data makes any difference ?

@raphaels17
Copy link
Author

the difference which is not showing is that i had set a title and a message, which someone is missing.
Like @avargaskun , we believe this is an issue between Onesignal and APNs. So my advice in the absence of consideration from OneSignal, is to migrate away from OneSignal.

@anand-ammathil
Copy link

Same issue here, spent hours debugging it :(.
Made us consider moving away from one signal all together.

@binodav
Copy link

binodav commented Jan 28, 2024

Is there anyone having this issue using paid plan ? I reported this issue to one signal multiple times since December but they refused to investigate, always replied me that everything is working fine from their side which made me think that they might stop supporting silent notifications for free tier, just that they don't make it public.

@elemans
Copy link

elemans commented Jan 30, 2024

After disabling and then enabling the app in the "Keys & IDs" section of the app settings in the OneSignal dashboard, silent push notifications seems to work again. I'm not sure if this is the result of my actions in the dashboard, or that the bug was already fixed earlier.

@alighani-zoral
Copy link

@everyone
The problem appears to have been resolved by One Signal. I am now receiving Silent Notifications without making any changes. A courteous clarification from their end could have saved us a considerable amount of time debugging this minor issue.

@emawby
Copy link
Contributor

emawby commented Jan 30, 2024

This appears to be working again. I will close the issue but please feel free to tag me to reopen if it resurfaces.

@emawby emawby closed this as completed Jan 30, 2024
@raphaels17
Copy link
Author

raphaels17 commented Jan 30, 2024

It is not working for us yet, also tried disabling and then enabling the app in the "Keys & IDs" section.
can anyone reopen ? @emawby

@emawby emawby reopened this Jan 30, 2024
@binodav
Copy link

binodav commented Jan 31, 2024

I tested and confirmed this is working again, wasted so much time debugging and implementing alternative solutions :(

@raphaels17
Copy link
Author

For what it is worth the onesignal tem is actively looking into it :" Hi there,

Currently we are still looking into this. Once we have more information, we will update you again!"

@emawby
Copy link
Contributor

emawby commented Feb 2, 2024

@raphaels17 I am no longer able to reproduce the issue so I am hoping I could get some more information on your setup in order to resolve this. You posted some api requests in order to reproduce the issue.

  1. Are you also unable to have your handler fired when using the dashboard?
  2. Do you have any other SDKs installed that might be interested in notifications and intercepting the handler (via swizzling)?

@raphaels17
Copy link
Author

  1. Are you also unable to have your handler fired when using the dashboard? Only when not silent I can provide you with notification

this is test test device 739c2606-3e54-4a79-aac1-c99106a00f17
with the exact same content ( i duplicate the notification)
`Onesignal ID Context Result
0c7bb528-5e42-4709-97fe-04b71cd77885 API silent not received
560e89b0-8860-4ce0-9179-a996e5150f15 Dashboard with title and content available received
26e09be0-6bb8-444d-8bb3-496fd808622 Dashboard only with content available not received

  1. Do you have any other SDKs installed that might be interested in notifications and intercepting the handler (via swizzling)? No i donnot

I notice there is an update 5.0.6 in the making in which @emawby you seem to be a major contributor . In there I see bits of code that are related to iOS such as

- name: Install the Apple certificate and provisioning profile uses: apple-actions/import-codesign-certs@v2 with: p12-file-base64: ${{ secrets.CERTIFICATES_P12 }} p12-password: ${{ secrets.CERTIFICATES_P12_PASSWORD }}

Should i update to an unpublish version to benefit from the fix ?

@raphaels17
Copy link
Author

raphaels17 commented Feb 9, 2024

After further debugging it is fixed for me as well .
I had to clean build then finally got something in :
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

this userinfo came in a different format than visible notification so i fixed that
var finalAdditionalData : [AnyHashable:Any] = safeAdditionalData if let customData = safeAdditionalData["custom"] as? [String: Any], let aData = customData["a"] as? [String: Any] { finalAdditionalData = aData }

Since I seem to be the last that was impacted i close the issue.
Don't know what has changed but thanks a million time !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants