iOS应用程序在除与Xcode连接的设备外的所有设备上都会崩溃

iOS应用程序在除与Xcode连接的设备外的所有设备上都会崩溃,ios,swift,Ios,Swift,当用户尝试注册一个新帐户时,我的应用程序崩溃并退出,但除了使用Xcode部署应用程序的设备外,任何设备上都会发生这种情况 所有设备都在开发者帐户中注册并运行iOS 11.4.1 以下是注册按钮功能: @IBAction func regButton(_ sender: Any) { usernameText = usernameTextField.text mobileText = mobileTextField.text emailText = emailTextFi

当用户尝试注册一个新帐户时,我的应用程序崩溃并退出,但除了使用Xcode部署应用程序的设备外,任何设备上都会发生这种情况

所有设备都在开发者帐户中注册并运行iOS 11.4.1

以下是注册按钮功能:

@IBAction func regButton(_ sender: Any) {

    usernameText = usernameTextField.text
    mobileText = mobileTextField.text
    emailText = emailTextField.text
    passwordText = passwordTextField.text
    fieldText = categoryTextField.text

    print(usernameText ?? "damn")
    print(mobileText ?? "damn")
    print(emailText ?? "damn")
    print(passwordText ?? "damn")
    print(fieldText ?? "damn")

    if(type=="Seeker")
    {
        let url1 = "http://app.alosboiya.com.sa/hourjob.asmx/insert_jobseeker?name="+usernameText!+"&phone="+mobileText!

        let url2 = "&email="+emailText!+"&password="+passwordText!+"&workex="+"companyDescText!"

        let url3 = "&category="+fieldText!+"&image="+"downloadURLGlobal!"

        let url4 = "&unpaidhour="+"string"+"&hourpaidlast30="+"string"+"&totalhourworked="+"string"+"&balance="+"string"+"&username="+usernameText!

        stringURL = url1 + url2 + url3 + url4
    }else
    {
        let url1 = "http://app.alosboiya.com.sa/hourjob.asmx/insert_company?name="+usernameText!+"&field="+fieldText!

        let url2 = "&phone="+mobileText!+"&email="+emailText!+"&password="+passwordText!+"&workex="+"companyDescText!"+"&crcopy="+"downloadURLGlobal!"+"&logo="+"string"+"&username="+usernameText!

        stringURL = url1 + url2
    }

    if Reachability.isConnectedToNetwork()
    {

        if(checkbox.on==true)
        {

        let url = URL(string: stringURL!)
        Alamofire.request(url!).responseString {

            (response) in

            let result = response.result.value
            do {
                if(result=="True")
                {

                    let alert = UIAlertController(title: "Registration Successfully", message: "Registration Done Successfully Congratulations",
                                                  preferredStyle: UIAlertControllerStyle.alert)
                    alert.addAction(UIAlertAction(title: "OK", style:
                        UIAlertActionStyle.default, handler: self.doSomething))
                    self.present(alert, animated: true, completion: nil)



                }else
                {
                    let alert = UIAlertController(title: "Registration Failed", message: "Registration Failed Please Try Again", preferredStyle: UIAlertControllerStyle.alert)

                    alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: { (action) in
                        alert.dismiss(animated: true, completion: nil)
                    }))

                    self.present(alert, animated: true, completion: nil)
                }

            }

        }

    }else
        {
            let alert = UIAlertController(title: "License Agreement", message: "Check to Agree Licence Agreement", preferredStyle: UIAlertControllerStyle.alert)

            alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: { (action) in
                alert.dismiss(animated: true, completion: nil)
            }))

            self.present(alert, animated: true, completion: nil)
        }

    }else
    {
        let alert = UIAlertController(title: "No Network Connection", message: "Connection Error Please Try Again", preferredStyle: UIAlertControllerStyle.alert)

        alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: { (action) in
            alert.dismiss(animated: true, completion: nil)
        }))

        self.present(alert, animated: true, completion: nil)
    }



}

如果用户点击按钮,但其中一个或两个文本字段均为空,则您的应用程序将因代码中使用的强制取消包装(!mark)而崩溃

示例:如果mobileText字段为空,则您的应用程序将崩溃:

 let url1 = "http://app.alosboiya.com.sa/hourjob.asmx/insert_jobseeker?name="+usernameText!+"&phone="+mobileText!
解决方法是使用guard语句

guard let usernameText = usernameTextField.text,
    mobileText = mobileTextField.text,
    emailText = emailTextField.text,
    passwordText = passwordTextField.text,
    fieldText = categoryTextField.text else {
return
}

您需要对TextFields进行验证,但即使它们不是空的,也会将构建配置更改为“Release”,然后运行它。希望当您通过Xcode运行时,它会崩溃,您可以调试问题所在。它已经“发布”,情况仍然是相同的。即使文本字段充满数据,这些设备也会崩溃。即使文本字段为空,使用Xcode运行的应用程序也会成功运行,没有任何问题(至少到目前为止,api允许这样做)因此问题与中文本字段的数据无关general@Mero_Android哪种部署方法(AppStore、Adhoc、Developer)在应用程序崩溃的设备上使用?其特殊方法您对安装特殊应用程序的设备有物理访问权限吗?如果有,则可以选择开发人员分发方法,该方法添加对调试器的支持,并在设备连接到带有调试器(Xcode)的计算机时允许您访问调试控制台