App crashes ONLY when connected to XCode - ios

My Swift app only seems to crash with EXC_BAD_ACCESS when my app is connected to XCode and I'm debugging. If I unplug my device and then run the app, it works flawlessly.
The app crashes at:
class AppDelegate: UIResponder, UIApplicationDelegate {
I'm pulling my hair out trying to solve this.

It's probably not a crash. More likely you have an Exception breakpoint and you're hitting it.

Try to replace your function with below one:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {}
or
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]!) -> Bool {}

That could be a pointer deallocating issue in the memory. That would be great if you can post more details about the error/crash info that you got, so that we can help you better. There are some solutions that you can try from this existing post, which was the similar problem(EXC_BAD_ACCESS) as you have: http://loufranco.com/blog/understanding-exc_bad_access

After a fiddling with the initial view controller I found that it only happened on the controller where my GMSMapView was. As it turns out, another user was having a similar problem here.
It turns out upgrading to iOS 8.4 solved the issue immediately. While I didn't use Dave's brilliant work around, I still give all the props and kudos to him!
Thank you everyone for sticking with me during this dark time in my life.

Related

How to write own crash report for Swift 5.1 application?

I'm trying to implement application crash report mechanism in locally using swift 5.1.
In here,
I'm trying to write Exception and Runtime errors to particular file which in application sandbox level.
I'm checking good place of class level catch exception and runtime errors.
I followed this link How should I use NSSetUncaughtExceptionHandler in Swift, but according to that, we cannot catch Swift run time errors.
I checked other answers and many of them are outdated, we are using ios 13.
Can someone suggest good way to track all errors and system crashes? I really appreciate your help and comments.
This is the good way to implement own crash report feature in application.
https://github.com/zixun/CrashEye/blob/master/CrashEye/Classes/CrashEye.swift
We can call add function like below way in AppDelegate class.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
CrashEye.add(delegate: self)
return true
}

Xcode not calling application delegate after opting out of SceneDelegate

When iOS 13 released, I opted out of using the new SceneDelegate through the normal procedures.
- SceneDelegate.swift does no longer exist
- There are no Scene related methods in AppDelegate
- Application Scene Manifest is removed from .plist
This worked great, and is how I've been running since (iOS 11.0 target, Xcode 11.2.1).
Last week I ran a build with deployment target as 13.0, then swapped back to 11.0.
Since then, the application delegate methods are no longer being called, such as.
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any])
The only thing that happens, that I can see is a log in console
Can't end BackgroundTask: no background task exists with identifier 15 (0xf), or it may have already been ended
I've triple checked all the settings above, but I can't get it to work like it used to.
The only thing that might be different is that the storyboards now defaults to 'automatic' (iOS 13.0, *) presentation mode, but I'm not sure how it was before.
Since automatic is only available from iOS 13+, it seems like something is messed up.
Does anyone have a clue?
Following up on the response in this thread:
applicationDidBecomeActive
applicationWillEnterForeground
etc are actually called.
I've tried cleaning the build, restarting Xcode, the mac, the device, clearing derived data etc.
So, I finally found the answer.
Turns out it's a good old
Instance Method Nearly Matches
func application(_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool
That Xcode completely ignored to report, and somehow managed to break in between building for iOS 11 > iOS 13 > iOS 11.
It's also strange because I verified them a couple of days ago with the documentation, both Apples & Firebase, and there was no difference between them.
In the end, it works now, yay.
If you don't need want to use the SceneDelegate then add below property in the AppDelegate file.
var window: UIWindow?
Add this line above didFinishLaunchingWithOptions function
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
{
// Override point for customization after application launch.
return true
}

NSException when using Firebase

I followed all the steps correctly to install Firebase to my iOS App and it still doesn't work. In the application method, I added FIRApp.configure() like so:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
FIRApp.configure()
return true
}
And I keep receiving NSException errors. Firebase seems to work on my Android Project, what's the deal with iOS?
I believe this is some sort of Swift 3 issue, because I encountered a similar problem. After looking over the internet, I believe that Firebase 3 hasn't updated to recent Swift Syntax located in Swift 3. Many other developers are having trouble with it as well. As an alternative, you could switch back from Xcode 8 and into 7, which would allow you to create your application which will work with current IOS, and when Firebase updates, it will be easy for you to migrate to Swift 3.
Hope this helps,
Morgan Gallant

Settings Blank On First Launch With registerDefaults

I have an issue with registerDefaults of NSUserDefaults with a settings bundle. Perhaps others have dealt with this issue and simply ignored but it's hit a point where I'm convinced this is either a bug or we're approaching the issue incorrectly.
Create a new dictionary and register it.
Launch the app.
Go to iOS Settings App
Go to your app settings and see the only things visible are location and camera.
Previous solution: Swipe up on the settings app to close and relaunch it then all of the settings appear.
Obviously this isn't ideal and although we have been dealing with the issue ever since iOS 7 I believe I am ready for a real solution since it's become more problematic for support lately. Has anyone had this work on first launch and if so, can you please share your technique?
Things we've tried.
Moving the register function to init() = same result
Calling register after didFinishLaunching = same result
Only add one option to narrow down issue = same result
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
var appDefaults = Dictionary<String, AnyObject>()
appDefaults["some_setting"] = true
appDefaults["some_setting2"] = false
NSUserDefaults.standardUserDefaults().registerDefaults(appDefaults)
NSUserDefaults.standardUserDefaults().synchronize()
return true
}
This was FINALLY fixed in iOS 10 with no changes necessary to the code above. THANK YOU APPLE!

App Crashes on AppDelegate Class Declaration with EXC_BAD_ACCESS CODE 1 on iOS 9.1/9.2

I installed XCode 7.1 and 7.2 to update my app for iOS 9.1 and 9.2 respectively, but each time I run the app on simulators or devices the app crashes on the AppDelegate's class declaration as shown below. However, I have also XCode 7.0 and when I run my app on iOS 9.0 it works fine without any issue !.
The problem even if I compile the app for iOS 9.0 it would crashes on any device running iOS 9.1 or 9.2, I tried to change the initial view controller to be a simple plain one but it seems that it never reaches the point of loading view controllers and never reaches the beginning of func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool.
It seems that Apple did something with iOS 9.1 & 9.2. The app is written in swift, I enabled NSZombie and breakpoints to catch exceptions but I get no clue from the logs.
Debug Navigator:-
AppDelegate Class Declaration
That happens to me almost every time in new versions of Xcode/Swift/iOS. When I have had this problem I have erased that line and written it again.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
This happens when you have not set you variable types correctly. Check how you declare them. In my case i was trying to access a Bool as UIColor.
I've generally had this happen when there is a storyboard problem. For example, an error in:
storyboard.instantiateController(withIdentifier: "FooView")
Try putting breakpoints around controllers that are being loaded around where you are crashing to see if that's the problem.

Resources