繁体   English   中英

用testflight轻按按钮时,应用崩溃

[英]App crashes when button tapped with testflight

我正在使用Swift 4.2开发应用,但是iOS应用崩溃时遇到了问题。 对我来说,一切正常,但是对于其他使用testflight安装应用程序的人而言,则无法正常工作。 错误是这样的。 在此处输入图片说明

这是添加处理程序的代码。

cell.btnBooknow.addTarget(self, action: #selector(pressBookNowButton(button:)), for: .touchUpInside)

这是一个按钮单击处理程序。

@objc func pressBookNowButton(button: UIButton) {
    guard let tagValue = self.arrListingBagHandler.object(at: button.tag) else {
        return
    }
    print(self.artworks)

    print(self.onlineStatus)
    print(self.arrSearchAddressResult)


    print(tagValue)
    let valueStatus = tagValue["IsOnline"] as! String
    let availability = tagValue["AvailabilityDays"] as! String
    let arr = Array(availableDays)
    print(valueStatus)
    print(arr)
    let arrAvailability = Array(availability)
    print(arrAvailability)
    let arr1 = availability.components(separatedBy: ",")
    print(arr1)

    let day = (presentDay!-1)
    let today = "\(day)"
    print(today)
    if arr1.contains(today)
    {
        availableToday = true
    }
    else
    {
        availableToday = false
    }

    if valueStatus == "1" && availableToday == true
    {
        let obj = self.storyboard?.instantiateViewController(withIdentifier: "bookingId") as! BookingViewController
        obj.dicBagHanlderDetail = tagValue
        self.navigationController?.pushViewController(obj, animated: true)
    }
    else 
    {
        let alert = UIAlertController(title: "Alert!", message: "You can't make booking because store is currently closed.", preferredStyle: .alert)
        let okAction = UIAlertAction(title: "OK", style: .cancel) { (actoin) in
        }
        alert.addAction(okAction)
        self.present(alert, animated: true, completion: nil)
    }

}

谁能帮帮我吗? 谢谢。

正如其他人建议的那样! 是潜在的崩溃。 尝试将其替换为保护值或默认值。 例如,您可以更改:

let valueStatus = tagValue["IsOnline"] as! String
let availability = tagValue["AvailabilityDays"] as! String

要使用默认值解决方案:

let valueStatus = tagValue["IsOnline"] as? String ?? "1"
let availability = tagValue["AvailabilityDays"] as? String ?? "5"

甚至可以提供更好的防护,例如在没有可用数据时显示警报:

guard let valueStatus = tagValue["IsOnline"] as? String,
    let availability = tagValue["AvailabilityDays"] as? String else {
    // Display alert in case of unavailable data (or simply return)
    let alert = UIAlertController(title: "Alert!", message: "You can't make booking because store is currently closed.", preferredStyle: .alert)
    let okAction = UIAlertAction(title: "OK", style: .cancel) { _ in }
    alert.addAction(okAction)
    self.present(alert, animated: true, completion: nil)
    return
}
// Continue as expected here...

请使用以下功能并解决问题。 我认为这是有可能的,因为强制转换了字符串和int值。

@objc func pressBookNowButton(button: UIButton) {
guard let tagValue = self.arrListingBagHandler.object(at: button.tag) else {
    return
}




let valueStatus = tagValue["IsOnline"] as? String ?? ""
let availability = tagValue["AvailabilityDays"] as? String ?? ""
let arr = Array(availableDays)

let arrAvailability = Array(availability)

let arr1 = availability.components(separatedBy: ",")

let value : Int = Int(presentDay) ?? 0
let day = (value-1)
let today = "\(day)"

if arr1.contains(today)
{
    availableToday = true
}
else
{
    availableToday = false
}

if valueStatus == "1" && availableToday == true
{
    let obj = self.storyboard?.instantiateViewController(withIdentifier: "bookingId") as! BookingViewController
    obj.dicBagHanlderDetail = tagValue
    self.navigationController?.pushViewController(obj, animated: true)
}
else
{
    let alert = UIAlertController(title: "Alert!", message: "You can't make booking because store is currently closed.", preferredStyle: .alert)
    let okAction = UIAlertAction(title: "OK", style: .cancel) { (actoin) in
    }
    alert.addAction(okAction)
    self.present(alert, animated: true, completion: nil)
}

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM