【问题标题】:SKCloudServiceController.requestAuthorization gets stuck upon authorizationSKCloudServiceController.requestAuthorization 在授权时卡住
【发布时间】:2021-03-08 17:22:19
【问题描述】:

我指的是下面的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。

【问题讨论】:

    标签: objective-c swift xcode controller apple-musickit


    【解决方案1】:

    通过实现以下函数来解决。它允许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
    }
    

    【讨论】:

      猜你喜欢
      • 2021-11-18
      • 2018-07-19
      • 1970-01-01
      • 1970-01-01
      • 2022-08-04
      • 2018-12-24
      • 1970-01-01
      • 2021-08-28
      • 2020-04-15
      相关资源
      最近更新 更多