gpt4 book ai didi

ios - 如果在 iOS10 中请求对本地通知的授权时发生错误,authorizationStatus 是什么?

转载 作者:行者123 更新时间:2023-11-28 15:26:21 25 4
gpt4 key购买 nike

在 iOS 10 中请求授权发送本地通知的代码可以写成:

 UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) 
{ (success, error) in
if let error = error {
print("Request Authorization Failed (\(error), \(error.localizedDescription))")
}
completionHandler(success)
}

我对那个“错误”有点困惑。如果出现错误怎么办?

“success:Bool”会是假的吗?如果答案是(yes false),那么

.authorizationStatus == .denied or .notDetermined  

最佳答案

如果发生错误,您将在控制台中看到此错误,success 将为 false。

来自 Apple 文档:

completionHandler.

The block to execute asynchronously with the results. This block may be executed on a background thread. This block has no return value and has the following parameters:

granted.

A Boolean value indicating whether authorization was granted. The value of this parameter is true when authorization for the requested options was granted. The value is false when authorization for one or more of the options is denied.

error.

An object containing error information or nil if no error occurred.

https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/1649527-requestauthorization

关于ios - 如果在 iOS10 中请求对本地通知的授权时发生错误,authorizationStatus 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45165025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com