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
494 stars 263 forks source link

Linking against a dylib which is not safe for use in application extensions #396

Closed olejnjak closed 2 years ago

olejnjak commented 6 years ago

Description:

Hi,

it is a bit odd that configuring OneSignal requires an app extension and OneSignal.framework is not app extension safe...

Environment

Xcode 9.4.1, integrating using Carthage 0.30.1 using Carthage integration guide

Steps to Reproduce Issue:

  1. create new project
  2. integrate using Carthage

Anything else: screen shot 2018-08-09 at 12 40 12

Nightsd01 commented 6 years ago

Our SDK doesn't use any extension-unavailable code in the extension service, so your app wouldn't get rejected. But the warning is certainly annoying.

You can also use Cocoapods, or link directly against our static binary, which would also get rid of the error, but neither of these things are necessary.

Eventually in the future I will look into either splitting out the extension-specific functionality into its own separate library, or I'll look into other approaches.

Droppix commented 6 years ago

+1

Nightsd01 commented 5 years ago

We're now working on a PR to fix this issue. Unfortunately it will need to be a breaking change so it will need to wait until our next major release (3.0)

Essentially we are splitting out extension-specific functionality into a separate (smaller) framework

Here is the current state of the PR: https://github.com/OneSignal/OneSignal-iOS-SDK/pull/427

otymartin commented 4 years ago

@Nightsd01 is there an existing branch with this fix? And what do you mean by or link directly against our static binary What does that mean?

jkasten2 commented 4 years ago

@otymartin The static OneSignal framework can be found here: https://github.com/OneSignal/OneSignal-iOS-SDK/tree/master/iOS_SDK/OneSignalSDK/Framework/OneSignal.framework

The PR #427 noted above just splits out the Notification Extension Service specific part of the SDK into its own target to make it smaller and to fix any warnings about APIs being referenced that are not available in that target. I don't believe it would fix the dynamic linking warnings.

otymartin commented 4 years ago

Ahh I see - so the warnings are here to stay until 3.0.0?

jkasten2 commented 4 years ago

Correct, it requires APPLICATION_EXTENSION_API_ONLY to be set in the Xcode project to fix the warning. However we can't do this until SDK is split into modules as I believe it would result in compiler errors otherwise.

otymartin commented 4 years ago

@JKalash So what do I set it to NO or YES and on what the OneSignal pod? or the Extension target? Or my apps main target?

jkasten2 commented 4 years ago

@otymartin It would be on the "OneSignal" framework project itself, like the following. https://stackoverflow.com/a/48863451/1244574 Again it will most likely create a compile issue as it is the same code base for the main target and the extension. Also the "not safe" warning is present since it doesn't know if it is referring to any APIs it can't use. However OneSignal has runtime guards so there isn't any real issues.

otymartin commented 4 years ago

@JKalash Ok, although I hate seeing warnings I can live with. it knowing it won't affect the actual push delivery and App Store review process.

Thanks

otymartin commented 3 years ago

@jkasten2 is this problem fixed?

emawby commented 3 years ago

@jkasten2 is this problem fixed?

@otymartin Unfortunately this issue is not simple to fix since it requires having a separate SDK for the App target and the notification service extension target with no shared symbols. We are still looking into a fix for this.

BergQuester commented 3 years ago

Still a problem here in June 2021.

summonerriftofficial commented 2 years ago

same problem

ben73 commented 2 years ago

I'm using OneSignal via SPM and have the same problem. Any solutions?

emawby commented 2 years ago

The solution for this requires modularizing the SDK and is being actively developed. I apologize for the inconvenience and thank you for your patience.

ahmedsafadii commented 2 years ago

same

koedal commented 2 years ago

Same. I try to have no warnings in projects but I'll have to continue waiting.

olejnjak commented 2 years ago

Well, changing SDK solved my problem 😃

Shadester commented 2 years ago

Seeing the same on SDK version 3.10.1 with Cocoapods.

apouche commented 2 years ago

Can anyone confirm that this is just a warning and will not be rejected by Apple if the extension is linked with theOneSignalXCFramework 3.10.1 dynamic library of OneSignal ?

olejnjak commented 2 years ago

It is the first answer here...https://github.com/OneSignal/OneSignal-iOS-SDK/issues/396#issuecomment-412171634

emawby commented 2 years ago

Hello! In order to fix this issue the SDK needed to be modularized to exclude references to UIApplication SharedApplication from the package imported in the Notification Service Extension.

There is now a beta release available that fixes this issue by providing a Cocoapods subspec or SwiftPM product OneSignalExtension to be used in Notification Service Extensions.

Note that there are a couple extra steps for Cocoapods to remove the warning, and all steps can be found in the release notes.

Also note that using OneSignalExtension should not be required by this release (it is intended to be a non-breaking change), so please report any issues you find upon upgrading.

hieuctrac commented 2 years ago

Hello! In order to fix this issue the SDK needed to be modularized to exclude references to UIApplication SharedApplication from the package imported in the Notification Service Extension.

There is now a beta release available that fixes this issue by providing a Cocoapods subspec or SwiftPM product OneSignalExtension to be used in Notification Service Extensions.

Note that there are a couple extra steps for Cocoapods to remove the warning, and all steps can be found in the release notes.

Also note that using OneSignalExtension should not be required by this release (it is intended to be a non-breaking change), so please report any issues you find upon upgrading.

I attempted to add the beta release to my project. I got it working for initial launch of my app but on subsequent launches of my app the OneSignal initialization code crashes.

jkasten2 commented 2 years ago

@hieuctrac Could you share the stack trace of the crash you are getting?

On the device you installed the app on, was it running an older version of the OneSignal SDK? If so what version?

If you install your app on another device (or fully uninstall it and reinstall it on the same device) do you see the same issue?

lhasiuk commented 2 years ago

I still get the warning, even though I've updated to 3.11.1 from 3.10.0, cleaned the build folders and recompiled everything. Is there something else I need to do? My project uses Objective-C, Cocoapods and has a deployment target of iOS 12.

jkasten2 commented 2 years ago

@lhasiuk Can you double check that you have made these changes to your project from the 3.11.0 release notes?

For Cocoapods

  • In your Podfile make sure that your Notification Service Extension target is nested in your App target.
  • Use pod OneSignal or OneSignalXCFramework (they are now identical) for your app target, and subspec OneSignal/OneSignalExtension or OneSignalXCFramework/OneSignalExtension for your Notification Service Extension target.
  • Then in your NotificationService class import OneSignalExtension instead of OneSignal
  • Lastly from the Other Linker Flags build setting in your Notification Service Extension target remove $(inherited) and -framework "OneSignal"
lhasiuk commented 2 years ago

@jkasten2 Thanks, I had not done those things. However, once I did all of them and double checked that I had, I started to have issues where the One Signal Extension is trying to include other Pods that are only used by my main application and since some of those pods reference things like [UIApplication sharedApplication], which is not available in an extension, I get errors during compilation. I tried making sure they were not mentioned in Other Linker Flags and even tried removing everything except -ObjC from Other Linker Flags, but it didn't help. Any suggestions how to solve that?

Sergozh commented 2 years ago

@jkasten2 Thanks, I had not done those things. However, once I did all of them and double checked that I had, I started to have issues where the One Signal Extension is trying to include other Pods that are only used by my main application and since some of those pods reference things like [UIApplication sharedApplication], which is not available in an extension, I get errors during compilation. I tried making sure they were not mentioned in Other Linker Flags and even tried removing everything except -ObjC from Other Linker Flags, but it didn't help. Any suggestions how to solve that?

I had the same issue. Did you find any solution?

lhasiuk commented 2 years ago

@Sergozh No, I have not found a solution yet. I'm hoping that @jkasten2 will offer further assistance.

sereisoglu commented 2 years ago

I'm using OneSignal with SPM and I'm getting the same warning. Are there any updates?

jkasten2 commented 2 years ago

@sereisoglu This warning should be resolved if you update to the 3.11.0 SDK and follow the SwiftPM instructions in the release notes:

For Swift Package Manager Use product OneSignal for your app target, and product OneSignalExtension for your Notification Service Extension target. Then in your NotificationService class import OneSignalExtension instead of OneSignal and change references of OneSignal in method bodies to OneSignalExtension

If the above is correct in your project can you share more details about your project?

  1. What version of Xcode
  2. Any other SDKs or libraries?
sereisoglu commented 2 years ago

@jkasten2 Thanks, this worked. I saw that there are 2 OneSignal libraries: https://github.com/OneSignal/OneSignal-iOS-SDK https://github.com/OneSignal/OneSignal-XCFramework What exactly is the difference between them?

jkasten2 commented 2 years ago

@sereisoglu The key thing is that you use OneSignalExtension in the OneSignalNotificationServiceExtension instead of OneSignal to fix this warning when using SwiftPM.

OneSignal-XCFramework was created as SwiftPM as using OneSignal-iOS-SDK take a lot longer to install since it git clones all history which takes a while to download on this repo.

sereisoglu commented 2 years ago

@jkasten2 When I add OneSignal-iOS-SDK using SPM, there are two options OneSignal and OneSignalExtension which one should I choose here? If I use OneSignal-XCFramework do I need to change OneSignal to OneSignalExtension?

jkasten2 commented 2 years ago

@sereisoglu Use OneSignal for your main app target Use OneSignalExtension for your Notification Service Extension target (OneSignalNotificationServiceExtension)

This is the same no matter if you use OneSignal-iOS-SDK or OneSignal-XCFramework (recommend for smaller dev download size) for SwiftPM.

elindberg-kt commented 1 year ago

If I use Cocoapods and see same issue as @lhasiuk and @Sergozh with complains about [UIApplication sharedApplication]. Any solution? Also, I see that the instructions on the Onesignal tutorial page is not updated either. I tried to move the Extension outside of the main target, but that gives a different error. Any clues on how to do it?

image
sabiland commented 1 year ago

I still get this warning with latest OneSignal framework. Latest Xcode, etc.

ridmaur commented 1 year ago

See this article for a workaround on how to get rid of this annoying warning. I did only use the OneSignalExtension package for my NotificationService extension and OneSignal package for my main app but that did not solve it.

JetForMe commented 1 year ago

So, is this still not fixed? Earlier in this thread it was going to be fixed for 3.x, but I'm getting it with 3.12.5, incorporated via SPM.

It’s been nearly five years.

rursache commented 1 year ago

Unbelievable how this is still not fixed as today. Any update on this @emawby? Maybe at least re-open the issue...?

Here is a way to at least silence the warning:

  1. Select your "Service Extension" (e.g. OneSignalServiceExtension)
  2. In "Build Settings" search for "other linker flags"
  3. Add -Xlinker -no_application_extension as a new flag
nan-li commented 1 year ago

Hi @JetForMe and @rursache, did you use OneSignalExtension and not OneSignal in your NotificationServiceExtension? Can you double check that you have made these changes to your project from the 3.11.0 release notes?

For Cocoapods

  • In your Podfile make sure that your Notification Service Extension target is nested in your App target.
  • Use pod OneSignal or OneSignalXCFramework (they are now identical) for your app target, and subspec OneSignal/OneSignalExtension or OneSignalXCFramework/OneSignalExtension for your Notification Service Extension target.
  • Then in your NotificationService class import OneSignalExtension instead of OneSignal
  • Lastly from the Other Linker Flags build setting in your Notification Service Extension target remove $(inherited) and -framework "OneSignal"

    For Swift Package Manager

  • Use product OneSignal for your app target, and product OneSignalExtension for your Notification Service Extension target.
  • Then in your NotificationService class import OneSignalExtension instead of OneSignal and change references of OneSignal in method bodies to OneSignalExtension

If you have made these changes and still seeing errors, can you share what your updated error is?