托管自定义服务中的后端错误
Backendless error in hosted custom service
我正在尝试在 Backendless
中使用 hosted custom service
我创建了一个自定义 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
不为空。
我现在尝试将 contatos
转换为 NSMutableArray
contatosNSMutableArray = contatos as! NSMutableArray
并且它停止向我重新调整错误,但它以数字形式返回响应 0
并且它没有保存数据。
此答案来自 Backendless 支持:
Swift code generation for version 3 does not work correctly.
I would recommend the following approach:
Modify your java code so it either declares public fields or get/set methods for the private fields.
Create the jar for the service and deploy in the 4.0 app. This is so you can generate the Swift code for it.
Once the swift code is generated, use it with your 3.x app.
我正在尝试在 Backendless
hosted custom service
我创建了一个自定义 jar library
并在 Backendless hosted custom service
中上传了它,但是当我尝试使用 Swift.
我的图书馆如下:
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
不为空。
我现在尝试将 contatos
转换为 NSMutableArray
contatosNSMutableArray = contatos as! NSMutableArray
并且它停止向我重新调整错误,但它以数字形式返回响应 0
并且它没有保存数据。
此答案来自 Backendless 支持:
Swift code generation for version 3 does not work correctly.
I would recommend the following approach:
Modify your java code so it either declares public fields or get/set methods for the private fields.
Create the jar for the service and deploy in the 4.0 app. This is so you can generate the Swift code for it.
Once the swift code is generated, use it with your 3.x app.