SKCloudServiceController.requestAuthorization gets stuck upon authorization

189 views Asked by At

I am referring to the following SKCloudServiceController.requestAuthorization method. Once the status is authorized, I would like to update @State var showStart = false so that the view can be pushed to the next one.

  if (showStart) {
        NavigationLink(destination: Main(), isActive: $showStart) {
            EmptyView()
        }.hidden()
    }
    SKCloudServiceController.requestAuthorization { (status) in
        if status == .authorized {
            print(AppleMusicAPI().fetchStorefrontID())
            showStart = true
        }
    }

But after this runs and the status is authorized, the app freezes and does not change showStart.

1

There are 1 answers

0
Papi On

Fixed by implementing the following function instead. It allows SKCloudServiceController.requestAuthorization to finish and then upon completion, set showStart to 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
}