OneSignal / OneSignal-iOS-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your native iOS app with OneSignal. https://onesignal.com
Other
496 stars 263 forks source link

[Bug]: incomplete migration guide to 5. #1341

Closed raphaels17 closed 10 months ago

raphaels17 commented 1 year ago

What happened?

I am trying to migrate from 3. to 5.

this is how i used to initialize // handle notifications

`OneSignal.initWithLaunchOptions(aunchOptions, appId: "my beautiful app id", handleNotificationReceived: { (notification) in

            guard let payload = notification?.payload else {
                return
            } // do things 

        }
    },
        handleNotificationAction: {  (result) in
        // do things

    }, settings: [kOSSettingsKeyAutoPrompt : true, kOSSettingsKeyInFocusDisplayOption : OSNotificationDisplayType.notification.rawValue])`

now i see import OneSignalFramework

OneSignal.initialize("YOUR_ONESIGNAL_APP_ID", withLaunchOptions: launchOptions) on the doc OneSignal.Notifications.addForegroundLifecycleListener(self)

about handleNotificationReceived, handleNotificationAction and setting ?

In particular, I am afraid this will not work in the background any longer

Can anyone help ?

Steps to reproduce?

migrate from 3 to 5. sdk

What did you expect to happen?

to have documentation for such change.

OneSignal iOS SDK version

5.0

iOS version

15

Specific iOS version

No response

Relevant log output

No response

Code of Conduct

emawby commented 1 year ago

Hello we appreciate feedback and are working on improving our migration guide. It sounds like you are migrating from the version 2 not version 3 since initWithLaunchOptions(launchOptions, appId: "my beautiful app id", handleNotificationReceived) does not exist in version 3. In version 3 we changed the notification events methods to: setNotificationWillShowInForegroundHandler and setNotificationOpenedHandler

The notification received handler was renamed since that handler does not fire if the app has been killed. There is no OneSignal callback for a notification being received in the background unless it is opened.

michaelhenry commented 11 months ago

Also noticed that some callbacks for the result state has been removed, for example OneSignal.setExternalUserId with login(), OneSignal.User.addTags and etc. So just to clarify, OneSignal will not provide the result state anymore for those methods? thanks

michaelhenry commented 11 months ago

Hi @emawby any update? Thanks

michaelhenry commented 11 months ago

and also for https://documentation.onesignal.com/docs/data-tag-implementation#getting-tags, can't access it from the static User instance.

nan-li commented 11 months ago

Hi @michaelhenry that is correct, we removed callbacks to methods like login or addTags. The SDK now uses a system of caching and retrying that will persist through app cold starts.

The getTags method is added in release 5.0.5. Can you check your version?

michaelhenry commented 11 months ago

@nan-li how about the getDeviceState? thanks

https://github.com/OneSignal/OneSignal-iOS-SDK/blob/edfd4151c5a85bd68826f5c44743dd34490b30ce/iOS_SDK/OneSignalSDK/SwiftPM/Public/Headers/OneSignal/OneSignal.h#L482

nan-li commented 11 months ago

Hi @michaelhenry, the information returned in OSDeviceState has been split up into their own sections. What piece of information are you looking for?

For example, if you are looking for the push subscription ID, it can be retrieved via OneSignal.User.pushSubscription.id or if you're looking for what the native permission is, it is available via let permissionNative: OSNotificationPermission = OneSignal.Notifications.permissionNative

raphaels17 commented 10 months ago

I am on OneSignal 5.0.5 , iOS17.2 Xcode 15 now and followed documentation for UNNotificationServiceExtension and but still i dont get how to get silent notification.

The document mention that i should get it in onwilldisplay and I have found in place to used func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void), none of it works

Basecally silent notification are not working

I do have this error in the console :

OneSignalNotificationServiceExtension[2071:220436] [User Defaults] Couldn't read values in CFPrefsPlistSource<0x10550cd60> (Domain: group.com.mybundle.onesignal, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd 2023-12-29 19:46:06.042835+0100 OneSignalNotificationServiceExtension[2071:220436] ERROR: OneSignal onNotificationReceived sendReceiveReceipt Failed for playerId: xyz error: (null)

TofPlay commented 6 months ago

I'm also trying to migrate from 3.11.2 to 5.1.5. With version 3.11.2 I could use setNotificationOpenedHandler What is the equivalent with 5.1.5?