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

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

Closed
olejnjak opened this issue Aug 9, 2018 · 42 comments · Fixed by #1083
Closed

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

olejnjak opened this issue Aug 9, 2018 · 42 comments · Fixed by #1083

Comments

@olejnjak
Copy link

olejnjak commented Aug 9, 2018

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
Copy link
Contributor

Nightsd01 commented Aug 10, 2018

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
Copy link

Droppix commented Aug 16, 2018

+1

@Nightsd01
Copy link
Contributor

Nightsd01 commented Sep 28, 2018

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: #427

@otymartin
Copy link

otymartin commented Jan 8, 2020

@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
Copy link
Member

jkasten2 commented Jan 8, 2020

@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
Copy link

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

@jkasten2
Copy link
Member

jkasten2 commented Jan 8, 2020

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
Copy link

@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
Copy link
Member

jkasten2 commented Jan 8, 2020

@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
Copy link

@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
Copy link

@jkasten2 is this problem fixed?

@emawby
Copy link
Contributor

emawby commented Oct 15, 2020

@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
Copy link

Still a problem here in June 2021.

@summonerriftofficial
Copy link

same problem

@ben73
Copy link

ben73 commented Dec 28, 2021

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

@emawby
Copy link
Contributor

emawby commented Jan 20, 2022

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
Copy link

same

@koedal
Copy link

koedal commented Feb 16, 2022

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

@olejnjak
Copy link
Author

Well, changing SDK solved my problem 😃

@Shadester
Copy link

Seeing the same on SDK version 3.10.1 with Cocoapods.

@OneSignal OneSignal deleted a comment Feb 18, 2022
@apouche
Copy link

apouche commented Feb 23, 2022

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
Copy link
Author

It is the first answer here...#396 (comment)

@emawby
Copy link
Contributor

emawby commented Apr 13, 2022

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
Copy link

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
Copy link
Member

@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
Copy link

lhasiuk commented May 18, 2022

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
Copy link
Member

@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
Copy link

lhasiuk commented May 23, 2022

@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
Copy link

Sergozh commented May 26, 2022

@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
Copy link

lhasiuk commented May 26, 2022

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

@sereisoglu
Copy link

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

@jkasten2
Copy link
Member

@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
Copy link

@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
Copy link
Member

jkasten2 commented Jun 21, 2022

@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
Copy link

@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
Copy link
Member

jkasten2 commented Jun 21, 2022

@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
Copy link

elindberg-kt commented Oct 7, 2022

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
Copy link

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

@ridmaur
Copy link

ridmaur commented Jan 23, 2023

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
Copy link

JetForMe commented May 7, 2023

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
Copy link

rursache commented Aug 7, 2023

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
Copy link
Contributor

nan-li commented Aug 7, 2023

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?

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

Successfully merging a pull request may close this issue.