swift simple app always crashing on simulator

rupps

My app is basically a webview with a locally stored webapp.

To support URL-Scheme mapping, I call the following function on viewDidLoad, to subscribe to UIApplicationDidBecomeActiveNotification, then when I get such message, I load a webapp into the UIWebView:

/**
* Setup the observer to get notifications about app activation
*/

func initObserver() {
    NSNotificationCenter.defaultCenter().addObserver(
        self,
        selector: "initWebApp",
        name: UIApplicationDidBecomeActiveNotification,
        object: nil);
}

/**
* Launches the WebApp, this is called from the observer, 
* and appDelegate.appParameters has possible parameters to the webapp
*/

func initWebApp() {
    var appDelegate=UIApplication.sharedApplication().delegate as AppDelegate;
    println ("- Launch Parameters: "+appDelegate.initParameters);
    let path=appDelegate.initParameters,
        url=NSURL(string: URL_BASE + "?" + (path ?? "")),
        requestObj=NSURLRequest(URL: url!);
    mWebView.loadRequest(requestObj);

}

However, when I init the webview in this way (coming from the observed handler) the simulator always crashes with the stacktrace enclosed below as soon as I click anywhere on the window.

On the contrary, If I don't subscribe to the event, and just call initWebApp() from viewDidLoad(), everything works fine (obviously URL Scheme mapping doesn't work, but I mean the webview and its app work 100% without crashing)

Can anybody take a look at this stack trace (it's always the same) and give me any pointers?

Is it a bad practice to manipulate UI objects such as UIWebView from an event handler? (I come from Android where you often have to change threads in similar situations)

2015-04-06 02:49:34.907 FunqTV[14285:518122] -[NSURL _effectiveStatusBarStyleViewController]: unrecognized selector sent to instance 0x7ae1cac0
2015-04-06 02:49:34.919 FunqTV[14285:518122] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL _effectiveStatusBarStyleViewController]: unrecognized selector sent to instance 0x7ae1cac0'
*** First throw call stack:
*** First throw call stack:
(
    0   CoreFoundation                      0x00648466 __exceptionPreprocess + 182
    1   libobjc.A.dylib                     0x02037a97 objc_exception_throw + 44
    2   CoreFoundation                      0x006502c5 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
    3   CoreFoundation                      0x00598bc7 ___forwarding___ + 1047
    4   CoreFoundation                      0x0059878e _CF_forwarding_prep_0 + 14
    5   UIKit                               0x00fd3fa8 +[UIViewController _currentStatusBarStyleViewController] + 75
    6   UIKit                               0x00e63c81 -[UIApplication _updateCurrentStatusBarViewControllerAppearance] + 59
    7   UIKit                               0x00eb06ea -[UIWindow _updateContextOrderingAndSetLayerHidden:] + 548
    8   UIKit                               0x00eade74 -[UIWindow _initWithFrame:debugName:scene:attached:] + 336
    9   UIKit                               0x00eadd1e -[UIWindow _initWithFrame:debugName:attached:] + 79
    10  UIKit                               0x00eadc7f -[UIWindow _initWithFrame:attached:] + 71
    11  UIKit                               0x011e6f27 -[UIAutoRotatingWindow _initWithFrame:attached:] + 80
    12  UIKit                               0x00eadc33 -[UIWindow initWithFrame:] + 63
    13  UIKit                               0x011e6eba -[UIAutoRotatingWindow initWithFrame:] + 72
    14  UIKit                               0x011e4e2a -[UITextEffectsWindow initWithFrame:] + 72
    15  UIKit                               0x00eae09a -[UIWindow initWithContentRect:] + 164
    16  UIKit                               0x011e4b12 -[UITextEffectsWindow(UIObjectsForPerScreen) _basicInitWithScreen:options:] + 141
    17  UIKit                               0x011e4bcf -[UITextEffectsWindow(UIObjectsForPerScreen) _initWithScreen:options:] + 182
    18  UIKit                               0x016fcf8c +[_UIObjectPerScreen objectOfClass:forScreen:withOptions:createIfNecessary:] + 556
    19  UIKit                               0x011e645c +[UITextEffectsWindow _sharedTextEffectsWindowforScreen:aboveStatusBar:allowHosted:matchesStatusBarOrientationOnAccess:] + 416
    20  UIKit                               0x011e65b4 +[UITextEffectsWindow sharedTextEffectsWindowForScreen:] + 121
    21  UIKit                               0x013d173a -[UIPeripheralHost(UIKitInternal) containerWindow] + 156
    22  UIKit                               0x013d178a -[UIPeripheralHost(UIKitInternal) containerRootController] + 34
    23  UIKit                               0x013c6e15 -[UIPeripheralHost currentState] + 38
    24  UIKit                               0x013c6f10 -[UIPeripheralHost isOnScreen] + 35
    25  UIKit                               0x013d3a6a -[UIPeripheralHost(UIKitInternal) _isCoordinatingWithSystemGestures] + 82
    26  UIKit                               0x00e70da1 -[UIApplication _shouldDelayTouchesForControlCenter] + 56
    27  UIKit                               0x00ebd506 -[UIWindow _shouldDelayTouchForSystemGestures:] + 41
    28  UIKit                               0x0128f8e8 -[_UISystemGestureGateGestureRecognizer touchesBegan:withEvent:] + 498
    29  UIKit                               0x00eb3946 -[UIWindow _sendGesturesForEvent:] + 567
    30  UIKit                               0x00eb4abf -[UIWindow sendEvent:] + 769
    31  UIKit                               0x00e79bb1 -[UIApplication sendEvent:] + 242
    32  UIKit                               0x00e89bf6 _UIApplicationHandleEventFromQueueEvent + 21066
    33  UIKit                               0x00e5dbc7 _UIApplicationHandleEventQueue + 2300
    34  CoreFoundation                      0x0056b98f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    35  CoreFoundation                      0x0056149d __CFRunLoopDoSources0 + 253
    36  CoreFoundation                      0x005609f8 __CFRunLoopRun + 952
    37  CoreFoundation                      0x0056037b CFRunLoopRunSpecific + 443
    38  CoreFoundation                      0x005601ab CFRunLoopRunInMode + 123
    39  GraphicsServices                    0x040152c1 GSEventRunModal + 192
    40  GraphicsServices                    0x040150fe GSEventRun + 104
    41  UIKit                               0x00e619b6 UIApplicationMain + 1526
    42  FunqTV                              0x0007dfbe top_level_code + 78
    43  FunqTV                              0x0007dffb main + 43
    44  libdyld.dylib                       0x027a5ac9 start + 1
    45  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

enter image description here

rupps

If I wrap the call to initWebApp() into a dispatch_async() block, it works:

   /**
    * Setup the observer to get notifications about app activation
    */

    func initObserver() {
        NSNotificationCenter.defaultCenter().addObserver(
            self,
            selector: "requestInitWebApp",
            name: UIApplicationDidBecomeActiveNotification,
            object: nil);
    }

   /**
    * Called from the observer. It now dispatches async a call to the init
    * function rather than calling it directly from the observer thread.
    */

    func requestInitWebApp() {
        println ("Dispatching async call to init webview");
        dispatch_async(dispatch_get_main_queue()) {
            self.initWebApp();
        }
    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Android app always crashing

Simple Android App Crashing

Android app crashing in simple app

Simple webView keeps crashing app

Simple WebView app keeps crashing

BB 10 App Crashing in device,but working good in simulator

requestLocation() always fails in the simulator with Swift 2

UIImage Download Returning nil and Crashing App (Swift)

App with Swift code crashing on launch after deployment

Component separated by string crashing app swift

App Keeps Crashing Found Nil Swift

Firebase app invite crashing on swift ios

iOS Simulator is Crashing on startup

My Spotify App keeps crashing because it's always on Full screen

Swift App crashes when closed in device/Simulator?

swift simple view app

Simple Counter app crashing on start up without any error

Simple Android App to launch URL in external browser keeps crashing

Rails app Staging environment crashing on Heroku with simple authentication

Pygame always crashing in python

React Native / Swift - In App Purchases code crashing randomly in sandbox and testflight

App crashing while fetching contact numbers from iPhone in SWIFT

xcode swift how to debug why the app is crashing after closing

iOS app crashing in release but not in development and Swift symbols are not resolved

Swift Searchbar App crashing while filtering 2 arrays

How to check nil for variables in swift and avoid app crashing?

Simple WebView Crashing

How to detect if app is being built for device or simulator in Swift

Why is TestCafe crashing on launch testing Electron app with simple command-line?