2016-12-27 6 views
1

他にも学校のクラスをテーブルビューに読み込むアプリを実行しようとしています。コードはそれは私にエラーを返し実行されると私はCloudKitのレコードを保存できません、なぜですか?

import UIKit 
import CloudKit 

class AddPostVC: UIViewController { 

    @IBOutlet weak var postText: UITextView! 
    let database = DatabaseController() 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIInputViewController.dismissKeyboard)) 

     view.addGestureRecognizer(tap) 
    } 

    //Calls this function when the tap is recognized. 
    func dismissKeyboard() { 
     //Causes the view (or one of its embedded text fields) to resign the first responder status. 
     view.endEditing(true) 
    } 

    @IBAction func postButtonPressed() { 
     let newPost = Post() 

     newPost.text = postText.text 
     newPost.user = CKReference(recordID: CKRecordID(recordName: UserDefaults.standard.string(forKey: "userRecordID")!), action: CKReferenceAction.none) 

     newPost.save() { _, error in 
      if error == nil { 
       DispatchQueue.main.async { 
        self.navigationController?.popViewController(animated: true) 

        self.dismiss(animated: true, completion: nil) 
       } 
      } else { 
       if !self.database.networkCheck() { 
        DispatchQueue.main.async { 
         self.displayErrorMessage(message: "It seems that there is no internet connection, try again") 
        } 
       } else { 
        DispatchQueue.main.async { 
         self.displayErrorMessage(message: error.debugDescription + ". Contact Apple or us for help") 
        } 
       } 
      } 

     } 

    } 

    func displayErrorMessage(message:String) { 

     let alert = UIAlertController(title: "Error", message: message, preferredStyle: .alert) 

     let dismissAction = UIAlertAction(title: "Dismiss", style: .default, handler: nil) 

     alert.addAction(dismissAction) 

     self.present(alert, animated: true) 

    } 

} 

[LogFacilityCK] Got a connection error for operation 69CB31B15036D50D: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.apple.cloudd" UserInfo={NSDebugDescription=connection to service named com.apple.cloudd}

は、この問題を解決する方法を誰もが知っていたコードは次のようになりますか?私はまだインターネット上のsolutiosnを見つけることができません。

答えて

3

この問題を引き起こした非常に重要なことは、cloudKitでCKRecord以外のタイプのレコードを保存することでした。私の場合、Post()クラスのsave()関数は、純粋なCKRecordではなく、CKRecordのサブクラスである自身を保存しようとしました。

もう1つのことは、それが動作することを停止し、記載されており、hereと回答したものです。

+0

あなた自身の質問に答えることとそれを回答として掲示するのは素晴らしい仕事です。 – MwcsMac

+0

本当に役に立ちます。ダニーに感謝します。 – EmptyStack

関連する問題