Swift: ActionExtension не открывается при объявлении Database.database (). Reference () - PullRequest
1 голос
/ 17 апреля 2020

Здравствуйте. В настоящее время я работаю над ActionExtension с использованием Firebase, чтобы обмениваться информацией через базу данных реального времени firebase.

Моя проблема заключается в том, что всякий раз, когда я объявляю «Database.database (). Reference ()», приложение не позвольте мне открыть расширение.

У меня есть код и журнал ошибок ниже

импорт UIKit импорт MobileCoreServices импорт Firebase импорт FirebaseAuth импорт FirebaseCore импорт FirebaseDatabase

class TextToClipViewController: UIViewController {
    
    @IBOutlet weak var TextToClip: UITextView!
    
    var convertedString: String?
    var uid: String?
    var ref = Database.database().reference() //<-- this is problem
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let textItem = self.extensionContext!.inputItems[0] as! NSExtensionItem
        let textItemProvider = textItem.attachments![0]
        
        if textItemProvider.hasItemConformingToTypeIdentifier(kUTTypeText as String) {
            textItemProvider.loadItem(forTypeIdentifier: kUTTypeText as String,
                                      options: nil,
                                      completionHandler: {
                                        (result, error) in
                                        self.convertedString = result as? String
                                        if self.convertedString != nil {
                                            //self.convertedString = self.convertedString!.appending(uid)
                                            DispatchQueue.main.async {
                                                self.TextToClip.text = self.convertedString!
                                            }
                                        }
                                        
            })
        }
        
        FirebaseApp.configure()
        let user = Auth.auth().currentUser
        
        let defaults = UserDefaults(suiteName: "group.JS.TossSync.share")
        let email = defaults?.string(forKey: "email") ?? "nothing"
        let password = defaults?.string(forKey: "password") ?? "nothing"
        
        if let user = user {
            uid = user.uid

            if textItemProvider.hasItemConformingToTypeIdentifier(kUTTypeText as String) {
                textItemProvider.loadItem(forTypeIdentifier: kUTTypeText as String,
                                          options: nil,
                                          completionHandler: {
                                            (result, error) in
                                            self.convertedString = result as? String
                                            if self.convertedString != nil {
                                                //self.convertedString = self.convertedString!.appending(uid)
                                                DispatchQueue.main.async {
                                                    self.TextToClip.text = self.convertedString!
                                                }
                                            }
                                            
                })
            }
        }
        else{
            if(email == "nothing" && password == "nothing"){
                TextToClip.text = "login to main app"
            }
                
            else{
                Auth.auth().signIn(withEmail: email, password: password) { user, error in
                  if let error = error, user == nil {
                    let alert = UIAlertController(title: "Sign In Failed",
                                                  message: error.localizedDescription,
                                                  preferredStyle: .alert)
                    
                    alert.addAction(UIAlertAction(title: "OK", style: .default))
                    
                    self.present(alert, animated: true, completion: nil)
                  }
                      
                  else{}
                }
            }
        }
    }

    @IBAction func done() {

      let returnProvider =
        NSItemProvider(item: convertedString as NSSecureCoding?,
                       typeIdentifier: kUTTypeText as String)

      let returnItem = NSExtensionItem()

      returnItem.attachments = [returnProvider]
      self.extensionContext!.completeRequest(
        returningItems: [returnItem], completionHandler: nil)
    }

    @IBAction func share(_ sender: Any) {
        
       let pusher: [String : String] = ["content/10": convertedString!, "flag": "0"]
        ref.child(uid!).child("clipboard").updateChildValues(pusher)
    }
}

2020-04-18 01:12:51.284690+0900 TossSync_ForApple[8976:2834488] [lifecycle  ] [u EFC68F17-B2CF-4CB0-8994-C50A12180DA3:m (null)] [JS.TossSync-Apple.Copy(1.0)] Connection to plugin interrupted while in use.
2020-04-18 01:12:51.285353+0900 TossSync_ForApple[8976:2834488] [lifecycle  ] [u EFC68F17-B2CF-4CB0-8994-C50A12180DA3:m (null)] [JS.TossSync-Apple.Copy(1.0)] Connection to plugin invalidated while in use.
2020-04-18 01:12:51.425523+0900 TossSync_ForApple[8976:2834495] [assertion] Error acquiring assertion: <NSError: 0x283b3a580; domain: RBSAssertionErrorDomain; code: 2; reason: "Specified target process does not exist">
2020-04-18 01:12:51.484291+0900 TossSync_ForApple[8976:2834495] [lifecycle  ] [u EFC68F17-B2CF-4CB0-8994-C50A12180DA3:m (null)] [JS.TossSync-Apple.Copy(1.0)] Connection to plugin interrupted while in use.
2020-04-18 01:12:51.484772+0900 TossSync_ForApple[8976:2834319] [ShareSheet] cancelled request - error: Extension cancelled by host.
2020-04-18 01:12:51.485174+0900 TossSync_ForApple[8976:2834319] [ShareSheet] Cannot connect to view controller in JS.TossSync-Apple.Copy - Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service on pid 8983 named JS.TossSync-Apple.Copy.viewservice was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid." UserInfo={NSDebugDescription=The connection to service on pid 8983 named JS.TossSync-Apple.Copy.viewservice was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid.} info {
    NSDebugDescription = "The connection to service on pid 8983 named JS.TossSync-Apple.Copy.viewservice was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid.";
}
...