2017-04-13 2 views
0

Ich arbeite mit CloudKit. Ich verwende diesen Code, um zu überprüfen, ob der Benutzer bei iCloud angemeldet ist.CKAccountStatus, wenn iCloudDrive nicht verwendet wird?

[[CKContainer containerWithIdentifier:my.container.id] 
    accountStatusWithCompletionHandler:^(CKAccountStatus accountStatus, NSError *error) { 
    // check accountStatus   
}]; 

Allerdings kommt der Kontostatus zurück, als CKAccountStatusNoAccount wenn ich angemeldet bin, haben aber icloud-Laufwerk ausgeschaltet. Ich würde erwarten, dass es CKAccountStatusAvailable stattdessen ist, da ich nicht iCloud Drive hier verwende.

Gibt es eine Möglichkeit zu überprüfen, ob der Benutzer in unabhängig von icloud-Laufwerk Nutzung angemeldet ist?

Antwort

0

Dieser Code überprüft, ob ein Benutzer iCloud zugreifen autorisiert ist. Das wird funktionieren.

func isAuthorized4Cloud() { 
    appDelegate = UIApplication.shared.delegate as! AppDelegate 
    container = CKContainer(identifier: "iCloud.ch.cqd.presenTagger") 
    publicDB = container.publicCloudDatabase 
    privateDB = container.privateCloudDatabase 
    var userID: CKRecordID! 
    container.fetchUserRecordID(completionHandler: { recordID, error in 
     guard error == nil else { 
      if let ckerror = error as? CKError { 
       if ckerror.code == CKError.requestRateLimited { 
        let retryInterval = ckerror.userInfo[CKErrorRetryAfterKey] as? TimeInterval 
        DispatchQueue.main.async { 
         Timer.scheduledTimer(timeInterval: retryInterval!, target: self, selector: #selector(self.files_searchSet), userInfo: nil, repeats: false) 
        } 
       } else if ckerror.code == CKError.zoneBusy { 
        let retryInterval = ckerror.userInfo[CKErrorRetryAfterKey] as? TimeInterval 
        DispatchQueue.main.async { 
         Timer.scheduledTimer(timeInterval: retryInterval!, target: self, selector: #selector(self.files_searchSet), userInfo: nil, repeats: false) 
        } 
       } else if ckerror.code == CKError.limitExceeded { 
        let retryInterval = ckerror.userInfo[CKErrorRetryAfterKey] as? TimeInterval 
        DispatchQueue.main.async { 
         Timer.scheduledTimer(timeInterval: retryInterval!, target: self, selector: #selector(self.files_searchSet), userInfo: nil, repeats: false) 
        } 
       } else if ckerror.code == CKError.notAuthenticated { 
        NotificationCenter.default.post(name: Notification.Name("noCloud"), object: nil, userInfo: nil) 
       } else if ckerror.code == CKError.networkFailure { 
        NotificationCenter.default.post(name: Notification.Name("networkFailure"), object: nil, userInfo: nil) 
       } else if ckerror.code == CKError.networkUnavailable { 
        NotificationCenter.default.post(name: Notification.Name("noWiFi"), object: nil, userInfo: nil) 
       } else if ckerror.code == CKError.quotaExceeded { 
        NotificationCenter.default.post(name: Notification.Name("quotaExceeded"), object: nil, userInfo: nil) 
       } else if ckerror.code == CKError.partialFailure { 
        NotificationCenter.default.post(name: Notification.Name("partialFailure"), object: nil, userInfo: nil) 
       } else if (ckerror.code == CKError.internalError || ckerror.code == CKError.serviceUnavailable) { 
        NotificationCenter.default.post(name: Notification.Name("serviceUnavailable"), object: nil, userInfo: nil) 
       } 
      } // end of guard statement 
      return 
     } 

     if error == nil { 
      userID = recordID 
      //print("fcuk1210 files_setup userID \(userID.recordName)") 
      NotificationCenter.default.post(name: Notification.Name("cloudConnected"), object: nil, userInfo: nil) 
     } 
    }) 
} 
Verwandte Themen