swift,为ios 7和8编写代码 [英] swift, write code for ios 7 and 8
问题描述
我有一个测试应用程序我正在用Swift编写,我想要定位iOS 7.但启用本地通知我需要添加
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))
但这个电话在iOS 7中不可用,所以我添加了
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
}
ios 8代码块仅在iOS 8(经测试)下运行,但在iOS 7中运行应用程序时,我仍然可以获得
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:未找到符号:_OBJC_CLASS _ $ _ UIUserNotificationSettings
引自:/var/mobile/Applications/AC73969D-1A4C-45AC-99CA-0B3982C1EE36/Timely.app/Timely
预期: /System/Library/Frameworks/UIKit.framework/UIKit
in /var/mobile/Applications/AC73969D-1A4C-45AC-99CA-0B3982C1EE36/Timely.app/Timely
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
我认为这是因为二进制文件包含iOS 7中不存在的api符号,但我如何解决这个问题?
I assume it's because the binary contains symbol to api that doesn't exist in iOS 7, but how do i resolve this?
推荐答案
不幸的是,我认为你遇到了当前的限制,请看这个
Unfortunately, I think you are running into a current limitation, see this
解决这个问题的唯一方法是添加一个Objective-C文件,然后使用 #if
宏并制作两个你从Swift调用的辅助函数(一个用于iOS8,一个用于iOS7)。我希望这会在某个时候得到修复。
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.
这篇关于swift,为ios 7和8编写代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!