我是一名初学者Swift Developer,正在使用Parse进行Swift迁移。 生产应用程序正在使用Swift 2并正常工作。 我将我的代码更新为Swift 3,因此应用程序现在正在启动,但我的Parse Cloud功能没有触发,我找不到原因。
这是代码
@IBAction func action_signup_v2(_ sender: UIButton) {
Mixpanel.sharedInstance().track("ios_signup_phone_number_sent")
sender.isEnabled = false
let phoneNumberKit = PhoneNumberKit()
print("Tapped send button")
let phone_number=text_field_signup.text
do {
let phoneNumber = try phoneNumberKit.parse(phone_number!, withRegion: "US")
let phoneE164: String = phoneNumberKit.format(phoneNumber, toType: .e164)
let phone_clean = String(phoneE164.characters.dropFirst(2)) as String
self.phoneNumber=phone_clean
print(phone_number as Any)
PFCloud.callFunction(inBackground: "send_code", withParameters: ["phoneNumber":phone_clean,"language":"en"]) {
(response: Any?, error: Error?) in
print("Parse function triggered")
if error == nil {
// If there is no error
print("no err")
self.performSegue(withIdentifier: "go_to_verify_controller", sender: self)
} else {
Mixpanel.sharedInstance().track("ios_error_signup_phone_number")
self.present_alert(title: "Oops", content: "Our servers are too busy please try again in a few moment.")
print(error ?? "There is an error");
}
}
}
catch {
print("Generic parser error")
self.present_alert(title: "Oops", content: "Please check the format of your phone number and try again.")
Mixpanel.sharedInstance().track("ios_error_signup_phone_number", properties : ["error_message":"generic parser error"])
}
}
以下是印刷品:
Tapped send button
Optional("(650) 460-3317")
以下是有关Parse
的更多信息 PFCloud
类提供与Parse Cloud Functions交互的方法。
* /
公开课PFCloud:NSObject {
/**
Calls the given cloud function *asynchronously* with the parameters provided.
@param function The function name to call.
@param parameters The parameters to send to the function.
@return The task, that encapsulates the work being done.
*/
open class func callFunction(inBackground function: String, withParameters parameters: [AnyHashable : Any]?) -> BFTask<AnyObject>
/**
Calls the given cloud function *asynchronously* with the parameters provided
and executes the given block when it is done.
@param function The function name to call.
@param parameters The parameters to send to the function.
@param block The block to execute when the function call finished.
It should have the following argument signature: `^(id result, NSError *error)`.
*/
open class func callFunction(inBackground function: String, withParameters parameters: [AnyHashable : Any]?, block: Parse.PFIdResultBlock? = nil)
}
答案 0 :(得分:1)
尝试将此功能更改为使用以下块运行:
(函数调用结束时执行的块):
PFCloud.callFunction(inBackground: "send_code", withParameters:["phoneNumber":phone_clean,"language":"en"] , block: { (response: Any?, error: Error?) in
if error == nil {
答案 1 :(得分:1)
Hello没有触发Everyone函数,因为Parse是ShutDown。 : - )
https://parseplatform.github.io Parse服务现在已关闭。对于那里的所有开发人员来说,很高兴帮助您构建应用程序。再见,祝你好运!如果您对迁移有任何疑虑,请参阅迁移指南或访问migration@parse.com。
答案 2 :(得分:0)
找到解决方案,在Swift Migration中,我忘了添加&#34; _&#34;在
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {