iOS App Crashes on Phone But Works Fine on Simulator

App crash on device but works on simulator iOS

The problem was in pods frameworks. Script generated by pods can't embed some frameworks correctly. I removed "[CP] Embed Pods Frameworks" script and add frameworks to "Embedded Binaries" by myself. And problem was solved.

iOS App Crashes on Phone but works fine on simulator

Try:

get{
println("display.text =\(display.text!)")
let formatter = NSNumberFormatter()
formatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
return formatter.numberFromString(display.text!)!.doubleValue
}

Because, NSNumberFormatter uses devices locale by default, it's possible that the decimal separator is not ".". For example:

let formatter = NSNumberFormatter()
formatter.locale = NSLocale(localeIdentifier: "ar-SA")
print(formatter.decimalSeparator!) // -> outputs "٫"
formatter.numberFromString("6.0") // -> nil

The formatter that uses such locales cannot parse strings like "6.0". So if you want consistent result from the formatter, you should explicitly specify the locale.

As for en_US_POSIX locale, see the document:

In most cases the best locale to choose is en_US_POSIX, a locale that's specifically designed to yield US English results regardless of both user and system preferences. en_US_POSIX is also invariant in time (if the US, at some point in the future, changes the way it formats dates, en_US will change to reflect the new behavior, but en_US_POSIX will not), and between platforms (en_US_POSIX works the same on iPhone OS as it does on OS X, and as it does on other platforms).

Swift app crashes on real device but works on simulator

I recently had a similar error.

I suspect you're trying to run the code on a pre 8.0 device. If that's the case, dateByAddingUnit is not available on your device (see the header)

@availability(iOS, introduced=8.0)

You can achieve what you're trying to do by using `dateByAddingComponents' - it's a little more cumbersome but should give you the same result. Try the following playground

import UIKit
import Foundation

var tuple:( Int, NSCalendarUnit) = (1, NSCalendarUnit.CalendarUnitDay)

var date = NSDate()

/* 8.0+ */
var yesterday = NSCalendar.currentCalendar().dateByAddingUnit(tuple.1, value: (-tuple.0), toDate: date, options: NSCalendarOptions.SearchBackwards)

/* 7.1 + */

let component = NSDateComponents()

if tuple.1 == NSCalendarUnit.CalendarUnitDay {
component.day = -tuple.0
}

var alsoYesterday = NSCalendar.currentCalendar().dateByAddingComponents(component, toDate: date, options: NSCalendarOptions.SearchBackwards)

Hope this helps! :)

Strange iOS app crashes on simulator

  1. Try going into "Edit Scheme" and unchecking all of the tests from "Build" clean your app And run it again.
  2. Go to TARGETS> Tests make sure you signin or if its ad hoc signed in the Test Target then set up a profile for the Test target or click Automatically Signing


Related Topics



Leave a reply



Submit