Firebase runTransactionBlock() в расширении общего доступа iOS

Мое расширение общего доступа имеет следующий код как часть сегмента didSelectPost():

override func didSelectPost() {
    if self.sharedURL != nil {
            // Send data to Firebase
            self.myRootRef.runTransactionBlock({
                (currentData:FMutableData!) in
                var value = currentData.value as? String
                // Getting the current value
                // and checking whether it's null
                if value == nil {
                    value = ""
                }
                // Setting the new value to the clipboard
                // content
                currentData.value = self.sharedURL?.absoluteString

                // Finalizing the transaction
                return FTransactionResult.successWithValue(currentData)
                }, andCompletionBlock: {
                    // Completion Check
                    (error:NSError!, success:Bool, data:FDataSnapshot!) in
                    print("DEBUG- We're done:\(success) and \(error)")
                }
            )
        }

        // This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.
        // Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context.
        self.extensionContext!.completeRequestReturningItems([], completionHandler: nil)
}

Я получаю следующую ошибку во время выполнения:

host connection <NSXPCConnection: 0x7fb84af2e8c0> connection from pid 16743 invalidated

Я считаю, что эта ошибка связана с andCompletionBlock и связана со следующей проблемой: информация об отладке при запуске сегодняшнее расширение

Как я могу чисто и успешно справиться со статусом завершения вышеуказанной транзакции?


person Bassem    schedule 27.11.2015    source источник


Ответы (1)


Как и в ответе, на который вы ссылаетесь, ошибка NSXPCConnection здесь не имеет значения.

Проблема в том, что .runTransactionBlock() является асинхронным, а .completeRequestReturningItems() будет вызываться и выходить из расширения до того, как вы получите значение из своей базы данных Firebase.

Попробуйте запустить .completeRequestReturningItems() в файле andCompletionBlock.

override func didSelectPost() {
    if self.sharedURL != nil {
            // Send data to Firebase
            self.myRootRef.runTransactionBlock({
                (currentData:FMutableData!) in
                var value = currentData.value as? String
                // Getting the current value
                // and checking whether it's null
                if value == nil {
                    value = ""
                }
                // Setting the new value to the clipboard
                // content
                currentData.value = self.sharedURL?.absoluteString

                // Finalizing the transaction
                return FTransactionResult.successWithValue(currentData)
                }, andCompletionBlock: {
                    // Completion Check
                    (error:NSError!, success:Bool, data:FDataSnapshot!) in
                            self.extensionContext!.completeRequestReturningItems([], completionHandler: nil)
                }
            )
        }

}
person David East    schedule 28.11.2015
comment
Я не могу получить доступ к firebase в своем расширении приложения, я использую obj c в качестве языка - person Ravi_Parmar; 11.07.2016