objective-c - SKCloudServiceController.requestAuthorization 在授权时卡住
问题描述
我指的是以下SKCloudServiceController.requestAuthorization
方法。一旦状态被授权,我想更新@State var showStart = false
以便可以将视图推送到下一个。
if (showStart) {
NavigationLink(destination: Main(), isActive: $showStart) {
EmptyView()
}.hidden()
}
SKCloudServiceController.requestAuthorization { (status) in
if status == .authorized {
print(AppleMusicAPI().fetchStorefrontID())
showStart = true
}
}
但在此运行并授权状态后,应用程序冻结并且不会更改 showStart。
解决方案
通过实现以下功能来修复。它允许SKCloudServiceController.requestAuthorization
完成,然后在完成后设置showStart
为 true。
func requestAccess(_ completion: @escaping(Bool) -> Void) {
SKCloudServiceController.requestAuthorization { (status) in
switch status {
case .authorized:
completion(true)
case .denied, .notDetermined, .restricted:
completion(false)
@unknown default:
completion(false)
}
}
}
requestAccess { (true) in
showStart = true
}
推荐阅读
- docker - 在 OPENSHIFT 上保护路线
- javascript - 如何在数组中插入对象(作为元素)
- c# - 如何从此 Json 中提取所有值进行断言?
- sql - 使用 JDBC 删除语句无效
- javascript - 如何按字典顺序对数组进行排序
- java - Android 通过滑动整个适配器视图填充一个条形图
- r - 将 2 列与 R 中的值相结合
- php - 多用户登录重定向页面 Codeigniter
- c# - C# for 和 foreach 循环的区别
- ios - Swift:没有调用 didRegisterForRemoteNotificationsWithDeviceToken