I've added Manager.m (iOS class) in my build phase in the watch kit extension. However, I got the following error
'sharedApplication' is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead
Here is the line in my Manager.m that is causing the problem.
AppDelegate *appDelegate =
(AppDelegate *)[[UIApplication sharedApplication] delegate];
I want to use code in Manager.m, but lines of code like these are causing issues and won't let me run the watch App. Is there a way around this? I don't want to rewrite the whole class just to accommodate watchkit.
Define/Add a macro (e.g. WATCH_KIT_EXTENSION_TARGET) in your watch kit extension's target build settings and use it to selectively build code. E.g. as sharedApplication is not available on iOS extension, so you can code like below
#ifndef WATCH_KIT_EXTENSION_TARGET
AppDelegate *appDelegate =
(AppDelegate *)[[UIApplication sharedApplication] delegate];
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With