Disable all notification observers in a certain viewController - ios

I used NSNotification.Name.UIApplicationDidBecomeActive in many places in my app. but I want to disable all of them in just a ViewController for example named vc. in vc I called NotificationCenter.default.removeObserver(self) in viewWillDisappear method. but when I opened a URL in Safari and use the back-to-app button to come back to my app all the notifications were triggered again.
is there a way to disable all of the notifications in my whole application and enable them again?

Related

UNUserNotificationCenterDelegate didReceive response for Local Notifications not called when app is not running

I am trying to use the new UserNotifications framework for local notifications. I redirect the user to a different viewcontroller when the notification is clicked/open. The notification is not handled properly by UNUserNotificationCenterDelegate didReceive method.
When the notification is in the foreground, and then it is clicked, it redirects to the right viewcontroller, however, when the app is closed and the notification is opened, the app is launched, however, the main viewcontroller is displayed instead.
Problem wasn't actually with the didReceive, but instead with the way the transitions were being made being viewcontrollers, due to methods returning before completion.
I was simulating a normal user flow programmatically. The problem with that is that tableview:didselectRowAt was returning before the performSegue method inside it was executed.
I ended up manually loading the VCs instead and explicitly calling UInavigationController:pushViewController(vc:animated:) to push them on the navigation stack.

Get notified when allowing notification setting is changed iOS swift

I have a scenerio where I have to turn on/off a switch when user enables/disables notifications for an app from system setting. We can determine if notification is enabled or not using UIApplication.shared.currentUserNotificationSettings?.types.contains(UIUserNotificationType.alert) but what I need is notify VC when the setting is changed.
In order for the user to change the settings he should enter the settings; therefore, app will go to background. I advise you to check the status u=in the AppDelegate in the willEnterForeground function and update the view controller. You may update the view controller by having an instance or by using Notification Center.

Perform action when opening app for the second time

When I open the app it fires the events viewDidLoad and viewDidAppear form my View Controller but when I close it and run it again it does not call any of them.
Any idea?
You need to read up on application states. Here is a link I found online outlining the different states:
http://www.techrepublic.com/blog/software-engineer/understand-the-states-and-transitions-of-an-ios-app/
What you really want is to be notified when your app becomes active.
Probably the easiest way is to implement the function applicationDidBecomeActive() in your app delegate. That will be called when your app becomes active as the foreground app either on launch, or when it returns to the foreground as the active app.
Note that if you want that notification sent to some object other than the app delegate you can listen for the UIApplicationDidBecomeActive notification.

iOS 8 Share extension: is there callback available to know if user quit the host app while the share extension is being presented?

While share extension view controller is being presented (visible), is there callback method that can be implemented in the extension's view controller to know when user presses home button which will cause the host app to resign active?
I have tried the following:
viewWillDisappear:
viewDidDisappear:
UIApplicationWillResignActiveNotification
UIApplicationDidEnterBackgroundNotification
None of the above works.
I need the callback so that when user closes the app, I would like to suspend all network operations that is currently running in the share extension process.
You can register for the following notifications (defined in NSExtensionContext):
NSExtensionHostWillEnterForegroundNotification
NSExtensionHostDidEnterBackgroundNotification
NSExtensionHostWillResignActiveNotification
NSExtensionHostDidBecomeActiveNotification
-viewWillDisappear:/-viewDidDisappear: only apply to the view controller used to present the share extension.

iPhone UILocalNotification load specific view

I have my local notification working, but when I click View to come back to the app, in the app delegate I am trying to load a specific view, but it wont take. Is this possible or not? It always just comes back to the last view viewed.
When you tap "View" on the notification, it takes you back to your application, and your application shows whatever it was showing before (if it was backgrounded) or is launched.
If you need to show a particular UI in response to the notification, consider implementing the <UIApplicationDelegate> method -[<UIApplicationDelegate> application:didReceiveLocalNotification:]. In that method you can inspect the notification and transition to the appropriate interface.

Resources