ApplicationWillTerminate in iOS 4.0

From the iPhone Application Programming Guide: Even if you develop your application using iPhone SDK 4 and later, you must still be prepared for your application to be terminated. If memory becomes constrained, the system might remove applications from memory in order to make more room. If your application is currently suspended, the system removes … Read more

Display a view or splash screen before applicationDidEnterBackground (to avoid active view screenshot)

I think the problem is that you are testing in simulator. On device, it should work fine. I tested this and it worked. Add an imageview with your splash image when app enters in background – – (void)applicationDidEnterBackground:(UIApplication *)application { UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.window.bounds]; imageView.tag = 101; // Give some decent tagvalue or … Read more

Detect if application: didReceiveRemoteNotification: fetchCompletionHandler: was called by tapping on a notification in Notification Center

The Apple docs are a bit confusing application: didReceiveRemoteNotification: fetchCompletionHandler: is used if your application supports the remote-notification background mode (ie you’re doing BackgroundFetch.) application: didReceiveRemoteNotification: is called when the OS receives a RemoteNotification and the app is running (in the background/suspended or in the foreground.) You can check the UIApplicationState to see if the … Read more

How to detect if code is running in Main App or App Extension Target?

You can use a preprocessor macro: In the project settings use the dropdown in the topbar to select your extension target: Then: Click Build Settings Find (or search) Preprocessor Macros under Apple LLVM 6.0 – Preprocessing Add TARGET_IS_EXTENSION or any other name of your choice in both the debug and release sections. Then in your … Read more

didReceiveRemoteNotification: fetchCompletionHandler: open from icon vs push notification

Ok I figured it out. The method is actually called twice (once when it receives the push, and once when the user interacts with the icon or the notification). – (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { if(application.applicationState == UIApplicationStateInactive) { NSLog(@”Inactive”); //Show the view with the content of the push completionHandler(UIBackgroundFetchResultNewData); } else if … Read more

Scheduled NSTimer when app is in background?

You shouldn’t solve this problem by setting a timer, because you’re not allowed to execute any code in the background. Imagine what will happen if the user restarts his iPhone in the meantime or with some other edge cases. Use the applicationDidEnterBackground: and applicationWillEnterForeground: methods of your AppDelegate to get the behavior you want. It’s … Read more

What is a “delegate” in Objective C’s iPhone development? [duplicate]

A delegate is a pointer to an object with a set of methods the delegate-holder knows how to call. In other words, it’s a mechanism to enable specific callbacks from a later-created object. A good example is UIAlertView. You create a UIAlertView object to show a short message box to users, possibly giving them a … Read more

App delegate methods aren’t being called in iOS 13

iOS 13 has a new way of sending app lifecycle events. Instead of coming through the UIApplicationDelegate they come through the UIWindowSceneDelegate which is a UISceneDelegate sub-protocol. UISceneDelegate has the important delegate methods. This change is to support multiple windows in iOS 13. There’s more information in WWDC 2019 session 212 “Introducing Multiple Windows on … Read more

Conditionally start at different places in storyboard from AppDelegate

I’m surprised at some of the solutions being suggested here. There’s really no need for dummy navigation controllers in your storyboard, hiding views & firing segues on viewDidAppear: or any other hacks. If you don’t have the storyboard configured in your plist file, you must create both the window and the root view controller yourself … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)