gpt4 book ai didi

java - 托管自定义服务中出现无后端错误

转载 作者:行者123 更新时间:2023-11-30 12:18:43 24 4
gpt4 key购买 nike

我正在尝试使用 hosted custom serviceBackendless

我创建了一个自定义jar library并上传至Backendless hosted custom service但当我尝试使用 Swift 中的 SDK 调用它时,它返回一个错误。

我的图书馆如下:

SalvarContatosLibrary.java

package com.mbaas.service;

import com.backendless.Backendless;
import com.backendless.servercode.IBackendlessService;

import java.util.ArrayList;

public class SalvarContatoLibrary implements IBackendlessService {

public boolean salvarContatos(ArrayList<Contato> contato) {

boolean retorno = true;

if(contatos == null || contatos() == 0) {
retorno = false;
} else {
for(Contato contato: contatos) {
Backendless.Persistence.save(contato);
}
}

return retorno;
}
}

Contato.java

package com.mbaas.service;

import java.util.Date;

/**
* Created by guilhermedupas on 12/07/17.
*/

public class Contato {

private Usuario usuario;
private int prioridade;

private String objectId;
private Date created;
private Date updated;
private String ownerId;
}

Usuario.java

package com.mbaas.service;

import java.util.Date;

/**
* Created by guilhermedupas on 12/07/17.
*/

public class Usuario {

private String nome;
private String foto;
private Date dataNascimento;
private String numeroTelefone;
private String telefoneE164;

private String objectId;
private Date created;
private Date updated;
private String ownerId;
}

我正在尝试调用该方法,代码如下:

Swift 代码

func salvarContato() {

let nomeServico = "SalvarContatoLibrary"
let versaoServico = "1.0.0"
let metodoServico = "salvarContatos"

let contatosNSArray = contatos as! NSArray

backendless?.customService.invoke(nomeServico, serviceVersion: versaoServico, method: metodoServico, args: contatosNSArray as! [Any],
response: { (result: Any?) -> Void in
print(result)

}, error: { (fault: Fault?) -> Void in
print("Erro contatos")
print("Server reported an error to save the User: \(fault)")
})
}

它返回的错误是:

Server reported an error to save the User: Optional(FAULT = '0' [ExceptionClass:"CodeRunnerException" {Msg:"Wrong number of arguments", Cause:"none"}] <ExceptionClass:"CodeRunnerException" {Msg:"Wrong number of arguments", Cause:"none"}> )

更新:

不,contatosNSArray不为空。

我现在尝试类型转换 contatosNSMutableArray

contatosNSMutableArray = contatos as! NSMutableArray

它停止向我重新调整错误,但它以数字形式返回响应 0并且它不保存数据。

最佳答案

这个答案来自 Backendless 支持:

Swift code generation for version 3 does not work correctly.

I would recommend the following approach:

  1. Modify your java code so it either declares public fields or get/set methods for the private fields.

  2. Create the jar for the service and deploy in the 4.0 app. This is so you can generate the Swift code for it.

  3. Once the swift code is generated, use it with your 3.x app.

关于java - 托管自定义服务中出现无后端错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45084584/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com