Xcode not calling application delegate after opting out of SceneDelegate - ios

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
}

Related

iOS Firestore App runs on Simulator but not on phone

I am developing an App that uses Firestore. The app runs fine on the Xcode simulator, but crashes when I try to run it on my phone. I get the following error message:
*** Terminating app due to uncaught exception 'FIRIllegalStateException', reason: 'Failed to get FirebaseApp
instance. Please call FirebaseApp.configure() before using Firestore'
I do call FirebaseApp.configure() in the didFinishLaunchingWithOptions:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
return true
}
I don't understand why it would run in the simulator and not on my phone. Any help would be appreciated.
Check your podfile for how you add the firebase cocoapods, It should be like this,
pod 'FirebaseCore'
pod 'Firebase/Messaging'
If your podfile different ,please remove old firebase related pods,insert this and install.
I discovered, on a Japanese code forum, what to do. I added the following code to the AppDelegate.swift file:
var window: UIWindow?
override init() { //初期化メソッドを追記
FirebaseApp.configure()
}
The app now runs both in the simulator and on my iPhone.

IOS - second launch of my app going auto in background

when I start my application from Xcode, the application works properly, but if I close and then open the app again, it goes into the background automatically without control. How can I fix this bug ?
There are some crash types those will not be happening when running the app via Xcode.
For example:
If the app launch takes too long, that app will be crashed. Basically it’s not a crash, but app needs to be launched quickly without delay which is expected by operating system.
So You need to make sure that you are not doing any heavy operations on Main Thread during app launch especially on below methods in AppDelegate
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
// Avoid heavy loads on main thread here
return true
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Avoid heavy loads on main thread here
return true
}
Also I received a crash a few years back when I tried to add an objective c struct to my NSObject class without allocating memory of struct variable. But this crash was unable to reproduce when I was running my app via Xcode and only happened when I launch the app without Xcode. So I made that struct variable as a pointer and did memory allocation as like (BoothStructure*)malloc(sizeof(BoothStructure) * count), after that there was no crash.
So please analyze your crash using crash logs as well and check if it meets any one of above scenario.
To check crash log of development build:
Open Xcode -> Connect your iOS device which has/had the crashed app -> Window -> Devices and Simulators -> View Device Logs
To check crash log of production build(you should add your developer account in Xcode that is used to publish your app):
Open Xcode -> Window -> Organizer -> Select your app from the list of apps -> Select crashes tab in segmented controller at top -> Select your build version.

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

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.

App crashes ONLY when connected to XCode

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.

Resources