Questions tagged [appdelegate]

In iOS, the app delegate is responsible for managing the app throughout its lifecycle by responding to events such as launch and termination.

2019 questions
11
votes
4 answers

Changing root view controller after iOS app has loaded.

In order to show my login screen when the app loads, and not after the user logs in, I have decided to add an auth object in NSUserDefaults when the user logs in successfully. When the app is launched that auth parameter is checked, and the view…
Misbah Khan
  • 372
  • 2
  • 3
  • 12
10
votes
2 answers

SwiftUI AppDelegate not being ran whenever app is opened

Here is a simple AppDelegate that I have made: import SwiftUI class AppDelegate: UIResponder, UIApplicationDelegate { private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool { …
Kunal Katiyar
  • 304
  • 2
  • 15
10
votes
1 answer

Application crashing with UIApplicationEndBackgroundTaskError

Context: My app is made using SwiftUI, which is a game using SpriteKit. When pressing the home button on my device, my app encounters an error called 'UIApplicationEndBackgroundTaskError'. The log looks like so: Can't end BackgroundTask: no…
George
  • 25,988
  • 10
  • 79
  • 133
10
votes
2 answers

How to use @EnvironmentObject to share data between AppDelegate and SceneDelegate/Views in SwiftUI

In SwiftUI 5.1, I want to use AppDelegate to create an userData object. userData will also contain BLE advertisement data, which will be updated from AppDelegate, too. These data should be available to the UI to display those values. In AppDelegate…
AnErd
  • 415
  • 3
  • 12
10
votes
4 answers

Xcode 11 beta: AppDelegate file doesn't have window global variable

I am facing an issue in Xcode 11 beta. The problem is that I am not getting default window variable declared in AppDelegate file. Is anybody facing this same issue?
Rashesh Bosamiya
  • 609
  • 1
  • 9
  • 13
10
votes
3 answers

Universal Links from Closed App not working

I have my app set-up to handle Universal links. We handle the retrieval of the URL, and the navigation given the URL inside of this function: func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler:…
Logan
  • 1,172
  • 9
  • 23
10
votes
1 answer

Open a ViewController from remote notification

I would like to open a ViewController when my app catches a remote notification. When I receive the notification I want to open a "SimplePostViewController", so this is my appDelegate : var window: UIWindow? var navigationVC:…
panic
  • 2,004
  • 2
  • 17
  • 33
9
votes
1 answer

SwiftUI 2 accessing AppDelegate

I did a small prototype which uses Firebase Cloud Messaging and the new SwiftUI 2 app life cycle. I added a custom AppDelegate via @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate and disabled method swizzeling for FCM to work.…
Carsten
  • 581
  • 4
  • 17
9
votes
2 answers

How to write unit tests for the AppDelegate?

I am doing a lot of setup inside my app delegate (mainly for CoreData) inside of applicationDidFinishLaunchingWithOptions. And was curious how i would go about testing code inside the appDelegate? Thanks
Luke97
  • 529
  • 3
  • 11
  • 27
9
votes
1 answer

What happens when you return `false` from `application(_:, continue:​, restoration​Handler:​)`?

I have enabled Universal Links in my app. The corresponding delegate call to handle those links is func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool { if…
Mischa
  • 15,816
  • 8
  • 59
  • 117
9
votes
3 answers

All 6 app delegate functions in swift 3 "nearly match optional requirement" - what is this? How to fix?

Downloaded the xcode 8.2 beta last night, converted most of my code but am now stuck with yellow warning symbols regarding the six functions of the app delegate: var window: UIWindow? func application(application: UIApplication,…
jonpeter
  • 599
  • 8
  • 28
9
votes
4 answers

Push notification data not getting when app launched directly by clicking app icon

I have a scenario in which app will get push notification and need to show that messages in home screen of my app, for that i saved the message array into user defaults from my app delegate and everything works well, but in following conditions it's…
Anshad Rasheed
  • 2,526
  • 1
  • 14
  • 32
9
votes
1 answer

How can I check when an app comes back into the foreground from the background, but not from push notification?

func application(application: UIApplication, didReceiveRemoteNotification data: [NSObject : AnyObject]) { var dat = JSON(data) if application.applicationState == UIApplicationState.Active { // app was already in the…
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
9
votes
1 answer

When do the appdelegate methods get called in relation to the view lifecycle methods of your initial view controller?

What is the sequence of methods that get called when your app loads, especially for these methods: applicationDidFinishLaunching viewDidLoad viewWillAppear applicationDidBecomeActive awakeFromNib
nvrtd frst
  • 6,272
  • 4
  • 28
  • 34
9
votes
3 answers

Connect together: AppDelegate, ViewController and XIB

I am new to the iOS programming and got stuck with one problem. What was done: I have created iOS application. Initially it had main.m, AppDelegate.h, AppDelegate.m and some other supporting files (not with code) that are usually created. Then I…
nickolay
  • 3,643
  • 3
  • 32
  • 40