OneSignal-iOS-SDK
OneSignal-iOS-SDK copied to clipboard
Add OneSignal to app without transitively linking against CoreLocation
It seems that the default behavior of OneSignal is to link against its OneSignalLocation, which in turn imports CoreLocation. This means that, even if the said code path is never reached, Apple will prompt you with a warning when submitting the app to the App Store if the NSLocationWhenInUseUsageDescription is not in the app's Info.plist.
This is, in my opinion, unfortunate as one would have to come up with a reason for NSLocationWhenInUseUsageDescription even if the feature will never be used. Judging from the code in OneSignalLocationManager, the dynamic features of the Objective-C runtime are heavily employed, which leads me to believe one has tried to use CoreLocation without employing the types exposed via the framework's interface. That is, in a way where CoreLocation is possibly linked, but not necessarily. This leads me to believe an attempt to make use of CoreLocation only for certain conditions when it is linked has been made, possibly to for occasions where the app programmer does not want to link against CoreLocation and manage the privacy implications. CoreLocation is however imported unconditionally.
As location services for push notifications are not strictly needed, I believe the cleanest approach would be to conditionally link against OneSignalLocation only if such features are necessary for the app consuming the OneSignal SDK. That is, the app programmer explicitly adds OneSignalLocation to the Podfile as a dependency when this functionality is needed.
Are my assumptions correct? Please advise me if I have missed anything related to how to disable CoreLocation for OneSignal. For the record, I'm using the Expo plugin for React Native to add OneSignal as a dependency.
Hi @hakonk, this is known to us. You are right, we did try to use the dynamic features of Objc to avoid this location detection by Apple. We have since ripped out OneSignalLocation from the native iOS SDK so clients can add the dependencies like this
target 'your_project_name' do
pod 'OneSignal/OneSignal', '>= 5.0.0', '< 6.0'
pod 'OneSignal/OneSignalInAppMessages', '>= 5.0.0', '< 6.0'
# If your app does not use CoreLocation, you can remove this:
pod 'OneSignal/OneSignalLocation', '>= 5.0.0', '< 6.0'
# Your other pods here
end
However, this is only available to clients using the native SDK directly - we do not have this available to cross-platform SDKs who import all the features at once.
Thanks for answering! Alright, I see. So I guess the config plugin for expo can be tweaked in order to only add certain additional features?
This would be considered a new feature we would investigate how best to support, as on react native now it is a single import via something like yarn add react-native-onesignal.
I see. Is that something you have discussed doing as well or should I submit a feature request?
This could also be done using macros, same as the flutter permission_handler does, where users add macros to exclude code from their compilation (expand the ios section to find an example like this):
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
# You can remove unused permissions here
# for more information: https://github.com/Baseflow/flutter-permission-handler/blob/main/permission_handler_apple/ios/Classes/PermissionHandlerEnums.h
# e.g. when you don't need camera permission, just add 'PERMISSION_CAMERA=0'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
## dart: PermissionGroup.calendar
'PERMISSION_EVENTS=1',
........
## The 'PERMISSION_LOCATION' macro enables the `locationWhenInUse` and `locationAlways` permission. If
## the application only requires `locationWhenInUse`, only specify the `PERMISSION_LOCATION_WHENINUSE`
## macro.
##
## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
'PERMISSION_LOCATION=1',
'PERMISSION_LOCATION_WHENINUSE=0',
]
end
end
end
Source code here.