Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if code runs in Today Extension or App

As UIApplication.sharedApplication() isn't available in the an iOS8 today widget/extension, how can I dynamically check if the code is currently running as widget or as app? When running the app I'd like to call e.g.

UIApplication.sharedApplication().registerUserNotificationSettings(settings)

When running the same code as widget this should simply be skipped. Is it possible to check for this?

like image 309
Bernd Avatar asked Nov 27 '25 04:11

Bernd


2 Answers

Make a separate prefix file for your extension, define a macro in the prefix file that is not defined in the app's prefix file. Then checking if this macro is defined will tell you whether you are in the extension or not. Alternately you can define the macro in the app's prefix file and not in the extensions' and check in the other direction.

like image 76
newacct Avatar answered Nov 29 '25 02:11

newacct


My solution:

#ifdef UIApplication
... //App
#else
... //Today Extension
#endif
like image 27
liruqi Avatar answered Nov 29 '25 02:11

liruqi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!