Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if iOS10 or lower during compile time

I am implementing new notifications, with UNUserNotificationCenter. But I need to keep it backwards compatible, therefore I have checks all over the place:

if #available(iOS 10.0, *) { ... }
else { ... }

Which seems to work fine in iOS10. To be able to use the UNUserNotificationCenter framework, I have to import:

import NotificationCenter

But it crashes the iOS9.3, because it does not know what it is. It is a compile time action, not a runtime action - so it means I can not put condition on the imports.If I create a separate class, and put

@available(iOS 10.0, *)
class ....

there the imports are also happening before the class implementation. How should I work around this issue?

like image 553
Async- Avatar asked Nov 09 '22 10:11

Async-


1 Answers

Try navigating to Build Phases->Link Binary with Libraries and add NotificationCenter and set the status to "optional" rather than "required".

like image 109
George McDonnell Avatar answered Dec 30 '22 16:12

George McDonnell