最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

iOS的云功能和返回

IT培训 admin 10浏览 0评论

iOS的云功能和返回

我想我的iOS应用程序雨燕整合使用OnCall中的云功能。然而,我的简单的服务拒绝发送回数据。

这里是我的功能:

exports.getText = functions.https.onCall((data, context) => {

    var public_token = data.public_token;


    if (!(typeof public_token === 'string') || public_token.length === 0) {
        // Throwing an HttpsError so that the client gets the error details.
        throw new functions.https.HttpsError('invalid-argument', 'The function must be called with ' +
            'one arguments "text" containing the message text to add.');
    }


    const docRef = admin.firestore().doc(`/PlaidUsers/` + public_token);

    docRef.get().then(function(doc) {

        if (doc.exists) {
            return {"text" : "test"};

        } else {
            return {"text" : "Document doesn't exist"};
        }

    }).catch(error => {
        return {"text" : "Error getting document"};

    });

});

它成功地部署到云功能

这是我简单的SWIFT代码:

 self.functions.httpsCallable("getText").call(["public_token" : self.userMap["plaidPublicToken"]]) { (result, error) in
                    if let error = error as NSError? {
                        if error.domain == FunctionsErrorDomain {
                            let code = FunctionsErrorCode(rawValue: error.code)
                            let message = error.localizedDescription
                            let details = error.userInfo[FunctionsErrorDetailsKey]
                            print(message)
                        }
                        // ...
                    }
                    if let text = (result?.data as? [String: Any])?["text"] as? String {
                        print (text)
                    }
                }

我不明白的错误只是一个空的结果。

回答如下:

在JavaScript中,thencatch是异步回调方法。你不能返回数据从他们的被包含函数返回。你的函数确实返回任何结果返回给客户端,这是因为在函数的顶层没有return语句。

thencatch均返回与他们的回调方法的返回值可以解决另一个承诺。因此,尝试把在承诺链顶层的回报:

return docRef.get().then(...).catch(...)

iOS的云功能和返回

我想我的iOS应用程序雨燕整合使用OnCall中的云功能。然而,我的简单的服务拒绝发送回数据。

这里是我的功能:

exports.getText = functions.https.onCall((data, context) => {

    var public_token = data.public_token;


    if (!(typeof public_token === 'string') || public_token.length === 0) {
        // Throwing an HttpsError so that the client gets the error details.
        throw new functions.https.HttpsError('invalid-argument', 'The function must be called with ' +
            'one arguments "text" containing the message text to add.');
    }


    const docRef = admin.firestore().doc(`/PlaidUsers/` + public_token);

    docRef.get().then(function(doc) {

        if (doc.exists) {
            return {"text" : "test"};

        } else {
            return {"text" : "Document doesn't exist"};
        }

    }).catch(error => {
        return {"text" : "Error getting document"};

    });

});

它成功地部署到云功能

这是我简单的SWIFT代码:

 self.functions.httpsCallable("getText").call(["public_token" : self.userMap["plaidPublicToken"]]) { (result, error) in
                    if let error = error as NSError? {
                        if error.domain == FunctionsErrorDomain {
                            let code = FunctionsErrorCode(rawValue: error.code)
                            let message = error.localizedDescription
                            let details = error.userInfo[FunctionsErrorDetailsKey]
                            print(message)
                        }
                        // ...
                    }
                    if let text = (result?.data as? [String: Any])?["text"] as? String {
                        print (text)
                    }
                }

我不明白的错误只是一个空的结果。

回答如下:

在JavaScript中,thencatch是异步回调方法。你不能返回数据从他们的被包含函数返回。你的函数确实返回任何结果返回给客户端,这是因为在函数的顶层没有return语句。

thencatch均返回与他们的回调方法的返回值可以解决另一个承诺。因此,尝试把在承诺链顶层的回报:

return docRef.get().then(...).catch(...)

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论