Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swift, write code for ios 7 and 8

Tags:

ios

swift

i got an test app I'm writing with Swift, I want to target iOS 7. But enable local notification I need to add

application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound 
    | UIUserNotificationType.Alert 
    | UIUserNotificationType.Badge, 
    categories: nil))

But this call is not available in iOS 7, so I added

var version:NSString = UIDevice.currentDevice().systemVersion as NSString;
if  version.doubleValue >= 8 {
    // ios 8 code
}

The ios 8 code block is only run in under iOS 8 (Tested), but when run the app in iOS 7 I still get

dyld: Symbol not found: _OBJC_CLASS_$_UIUserNotificationSettings Referenced from: /var/mobile/Applications/AC73969D-1A4C-45AC-99CA-0B3982C1EE36/Timely.app/Timely Expected in: /System/Library/Frameworks/UIKit.framework/UIKit in /var/mobile/Applications/AC73969D-1A4C-45AC-99CA-0B3982C1EE36/Timely.app/Timely

I assume it's because the binary contains symbol to api that doesn't exist in iOS 7, but how do i resolve this?

like image 737
Charlie Wu Avatar asked Jun 17 '14 05:06

Charlie Wu


2 Answers

Unfortunately, I think you are running into a current limitation, see this

What is the Swift preprocessor equivalent to iOS version check comparison?

The only way to get around this is to add an Objective-C file, and then use #if macros and make two helper functions that you call from Swift (one for iOS8 and one for iOS7). I expect this will be fixed at some point.

like image 177
Lou Franco Avatar answered Oct 21 '22 15:10

Lou Franco


In Beta6 it appears that some (all?) of the linking problems have been fixed. Apps linked with UIAlertAction and UIAlertController used to fail to launch on 7.1, but now will launch. You still cannot use them in 7.1, but you can test for iOS version and use the older objects.

like image 34
David Reich Avatar answered Oct 21 '22 16:10

David Reich