我试图找到UNNotificationRequest对象的预定开火日期.
我正在提取这样的待处理通知请求:
UNUserNotificationCenter.current().getPendingNotificationRequests { (notifications) in
let pendingNotifications : [UNNotificationRequest] = notifications
}
Run Code Online (Sandbox Code Playgroud)
然后我尝试访问每个UNNotificationRequest对象的触发日期.
我可以按如下方式访问UNNotificationTrigger,但无法找到访问通知的计划发布日期的方法.
let notification = pendingNotifications[indexOfNotification]
let trigger : [UNNotificationTrigger] = notification.trigger
Run Code Online (Sandbox Code Playgroud)
我已经能够访问一些通知的日期,如下所示:
let date = trigger.value(forKey: "date") as! Date
Run Code Online (Sandbox Code Playgroud)
这适用于使用UNUserNotificationCenter安排的通知,但在尝试访问iOS 10之前安排的通知日期时出现以下错误.
由于未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[valueForUndefinedKey:]:此类不是关键日期的密钥值编码兼容.
是否有一种方法可以同时支持新旧通知.
谢谢.
我在XCode 8.2.1中向我的代码添加文档时遇到了问题.
这是我的代码:
/// Test documentation method
///
/// - Parameter string: The input string
/// - Returns: The output bool
func testMethod(string:String) -> Bool {
if string == "YES" {
return true
}
return false
}
Run Code Online (Sandbox Code Playgroud)
文档在快速帮助窗口中按预期显示,但描述未显示在代码自动完成窗口中.
有没有办法让描述显示在自动完成框中,如下图所示:
谢谢.
我在Xcode 10(iOS 12 Beta)中捐赠自定义意图时遇到问题.
我创建了一个自定义框架,它在我的主应用程序目标和我的'OrderIntent'目标之间共享.
我创建了一个.intentdefinition文件,其目标成员资格设置为我的自定义框架(下面的屏幕截图).
我在主应用程序中嵌入了"Intents Extension"和"Intents UI Extension".
我还在添加了Intents扩展(下面的截图)时创建的两个info.plist文件中添加了'OrderIntent'到NSExtension-> NSExtensionAttributes-> IntentsSupported.
我正在尝试捐赠这样的意图:
INPreferences.requestSiriAuthorization { (status) in
if status != INSiriAuthorizationStatus.authorized {return}
let orderIntent = OrderIntent()
orderIntent.product = "Test product"
orderIntent.quantity = 2
let interaction = INInteraction(intent: customIntent, response: nil)
interaction.donate { (error) in
if error != nil {2
if let error = error as NSError? {
print(error)
}
} else {
print("success")
}
}
}
Run Code Online (Sandbox Code Playgroud)
当用户点击应用程序中的按钮时,上面的代码会运行.
我也设置了这样的intent处理程序:
class IntentHandler: INExtension {
override func handler(for intent: INIntent) -> Any …Run Code Online (Sandbox Code Playgroud)