I'm adding support for LiveActivities/Widgetkit for my iOS app. I'm still supporting older versions for iOS 14+. When checking if the user returned to the app through the LiveActivity in my SceneDelegate:
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
if #available(iOS 16.2, *), isLiveActivity(activity: userActivity) {
...
} else {
let _ = handleDynamicLink(url: userActivity.webpageURL)
}
}
with
@available(iOS 16.2, *)
public func isLiveActivity(activity: NSUserActivity) -> Bool {
return activity.activityType == NSUserActivityTypeLiveActivity
}
Now the issue is no matter how I wrap it in #available(iOS 16.2, *) or even if I don't call isLiveActivity
at all, just the presence of NSUserActivityTypeLiveActivity
in the code anywhere will, on older iOS versions (tested on simulator only) throw the error:
dyld: Symbol not found: _NSUserActivityTypeLiveActivity
How am I supposed to include this check if I can't even include the symbol anywhere in my code ?
I would have assumed NSUserActivityTypeLiveActivity
to be a compile time constant, but it seems like it's dynamically looked up and crashes, since it isn't available in older versions of WidgetKit.
I think it is a bug in the SDK and recommend you file a bug with Apple about it.
As a workaround you could do:
The reason why I think it is a bug because looking at the documentation, NSUserActivityTypeLiveActivity we see it marked as iOS 14.0+ but if we were to launch the simulator with debugging (
DYLD_PRINT_LIBRARIES
environmental variable) as per iOS Crash Dump Analysis we see it complain:If we were to go into the above
DYLD_ROOT_PATH
we could check usingnm
that the global variableNSUserActivityTypeLiveActivity
is not present because the following command yields no matches:So the global variable NSUserActivityTypeLiveActivity needs to be marked properly in the WidgetKit source code as not being available until iOS 16.1.