【发布时间】:2016-03-23 04:48:11
【问题描述】:
我有以下代码:
func setupShortcutItems(launchOptions: [NSObject: AnyObject]?) -> Bool {
var shouldPerformAdditionalDelegateHandling: Bool = false
if (UIApplicationShortcutItem.respondsToSelector("new")) {
self.configDynamicShortcutItems()
// If a shortcut was launched, display its information and take the appropriate action
if let shortcutItem: UIApplicationShortcutItem = launchOptions?[UIApplicationLaunchOptionsShortcutItemKey] as? UIApplicationShortcutItem {
// When the app launched at the first time, this block can not called.
self.handleShortCutItem(shortcutItem)
// This will block "performActionForShortcutItem:completionHandler" from being called.
shouldPerformAdditionalDelegateHandling = false
} else {
// normal app launch process without quick action
self.launchWithoutQuickAction()
}
} else {
// Less than iOS9 or later
self.launchWithoutQuickAction()
}
return shouldPerformAdditionalDelegateHandling
}
我在UIApplicationShortcutItem.respondsToSelector("new") 上收到以下“警告”,上面写着:
Objective-c 选择器不推荐使用字符串文字,请改用“#selector”
警告自动将代码替换为:
UIApplicationShortcutItem.respondsToSelector(#selector(FBSDKAccessToken.new))
但是这不能编译,因为new() 不可用。
在这种情况下我应该使用什么?
【问题讨论】:
-
你为什么要测试选择器
new?我在这里看不到任何发送new消息的代码。
标签: ios objective-c iphone swift