2017-05-17 15 views
1

Appleは非常に明確です。すべてのビデオで、「エラーを処理するCloudKitアプリケーションと、動作しないアプリケーションとの違いは、 t "である。しかし、私は、各エラーが何を意味するのかについての適切なリストを見つけることができません。どのオペレーションは、さまざまなCKOperationsに対してうまくいったCloudKitエラー処理のコードを実行します。さらに悪いことに、多くの例ではエラーはまったく処理されず、Appleからもドキュメントを見つけることはできません。CloudKit - 完全で完全なエラー処理の例

誰もが完全に完全な例を共有できますか? どのオペレーションが何を投げることができるリスト?

This postには、エラーの一覧と各エラーの簡単な説明が表示されます。 Appleが推奨するエラー処理の完全かつ完全な例を具体的に探しているので、この新しい投稿を作成しました。他の投稿には不完全な例があり、特定の質問をしています。私はコメントにこの記事を強調しました。これは、それぞれのエラータイプの簡単な説明が役に立つためです。短いが含まれてい

+0

ここ

例... [この記事](http://stackoverflow.com/a/43575025/3433061)ここで各エラーの説明。 – robwithhair

+0

Appleが推奨するエラー処理の完全かつ完全な例を具体的に探しているので、私はこの新しい投稿を作成しました。あなたが言及した投稿には不完全な例があり、特定の質問をしています。上記の記事は、各エラータイプについての簡単な説明が含まれているので、すでに強調しておきます。 – robwithhair

+0

https://developer.apple.com/reference/cloudkit/ckerrorcode – paper1111

答えて

1

ロブ、私が見つけた

func files_saveNotes(rex: Int) { 
    var localChanges:[CKRecord] = [] 

     let newRecordID = CKRecordID(recordName: sharedDataAccess.returnRexID(index2seek: rex)) 
     let newRecord = CKRecord(recordType: "Note", recordID: newRecordID) 

     let theLinkID = CKReference(recordID: sharedDataAccess.iCloudID, action: .deleteSelf) 
     let thePath = sharedDataAccess.fnGet(index2seek: rex) 
     newRecord["theLink"] = theLinkID 
     newRecord["theNo"] = rex as CKRecordValue? 
     newRecord["thePath"] = thePath as CKRecordValue? 



     let miam = sharedDataAccess.fnGetText(index2seek: rex) 
     let range = NSRange(location: 0, length: miam.length) 
     let dataMiam = try? miam.data(from: range, documentAttributes: [NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType]) 

     newRecord["theRTF"] = dataMiam as? CKRecordValue 


    localChanges.append(newRecord) 
    let records2Erase:[CKRecordID] = [] 

    let saveRecordsOperation = CKModifyRecordsOperation(recordsToSave: localChanges, recordIDsToDelete: records2Erase) 
    saveRecordsOperation.savePolicy = .allKeys 
    saveRecordsOperation.perRecordCompletionBlock = { record, error in 
     if error != nil { 
      //print(error!.localizedDescription) 
     } 
     // deal with conflicts 
     // set completionHandler of wrapper operation if it's the case 
    } 
    saveRecordsOperation.modifyRecordsCompletionBlock = { savedRecords, deletedRecordIDs, error in 
     self.theApp.isNetworkActivityIndicatorVisible = false 

     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_saveNotes), 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_saveNotes), 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_saveNotes), 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 { 
      //print(error!.localizedDescription) 
     } else { 
      // 
     } 
    } 

    saveRecordsOperation.qualityOfService = .background 
    privateDB.add(saveRecordsOperation) 
    theApp.isNetworkActivityIndicatorVisible = true 
} 
+0

ありがとうございます! NotificationCenterを使用してユーザーに適切な応答を表示することをお勧めします。私は網羅的なスイッチがすべてのエラーが処理されたことを保証し、将来のエラーへの追加はコンパイラエラーをユーザに通知することを考慮していましたか?しかし、すべてのCKOperationsがすべてのCKErrorタイプをスローできるわけではないので、多くのエラーは必要ないようです。残念ながら、どの操作でどのようなエラーが発生するかのリストはありません。少なくとも私は1つを見つけていない。 – robwithhair