Get notified when allowing notification setting is changed iOS swift - ios

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.

Related

Remote Notification 'application:didFinishLaunchingWithOptions:' method not called

Target: 7.0 and UP
Testing on: iPhone6 Device
I have been testing Regular Push Notifications (Remote).
I have discovered that if a user clicks on the app icon -- the "applicationDidFinishLaunching:" method is never called.
I have been reading and re-reading the guide on "Handling Local and Remote Notifications" and to confirm that I understood everything referred to: Handling Remote Notifications
It says If a user taps the default button in the alert or taps (or clicks) the app icon, then the app should call its delegate "application:didFinishLaunchingWithOptions" method. And if its a remote notification, it should call "application:didReceiveRemoteNotification:fetchCompletionHandler:".
Neither one of these methods get called if I click on the app icon.
The only method that does get called is applicationWillEnterForeground.
I do have a storyboard file. So the way it loads:
--> navigation controller --> table view controller --> so on
Am I supposed to somehow set the appDelegate in the storyboard file?
I have done a lot of research and so far I have had no luck.
My push alerts do come through so I know that it works. I just haven't been able to determine why these other methods are not being called when the user clicks on the app icon.
Any suggestions or help is appreciated.
The only solution if you want to handle when a user clicks on the app icon is to either A.) set up silent notifications or B.) Set up something on your server so that you can make a request to it to find out if there was a new update.

IOS push notification delete

I use a phone gap plugin and xcode 5.
Lets see the example of the problem:
The application is in background or closed.
I send the notification.
User sees the notification pop up, without clicking on it.
I send another notification.
If user open notification bar it will see two notification actually i want
to delete the previous some how and present to user only the second notification.
The eqvivalent in java is NotificationManage.cancelAll();
For now each/all notification i send are shown when user open notifications bar.
Any help appreciated.
You have (the app has) no control over that.
The user controls how many notifications they see in notification center. Notifications can be removed by the user and will be removed when acted upon (the app is opened from the notification).
You can do this by [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
in the method didReceiveRemoteNotification. In this way notification center will be cleared.

Differentiate when UIApplicationDidBecomeActiveNotification is being called

In my app, if UIApplicationDidBecomeActiveNotification is dispatched I present a modal security unlock view.
Everything is working fine except UIApplicationDidBecomeActiveNotification seems to get called whenever the iOS shows the "The App would like to use your current location" popup.
Is there a way to differentiate when UIApplicationDidBecomeActiveNotification is being called?
I need to show the security unlock view when the app returns from the background.
Look at using the UIApplicationWillEnterForegroundNotification notification instead.

How to tell whether user opened app with notification with iOS 7 remote-notification background mode?

According to didReceiveRemoteNotification when in background , we used to be able to handle the user opening the app by clicking the action button on a push notification (or swiping on the push notification, depending on how the user sees push notifications) by implementing -application:didReceiveRemoteNotification: and then checking inside the method whether the application's applicationState was not active.
In iOS 7, there's the new remote-notification background mode, which allows the app to perform background fetch when a remote notification is displayed to the user (without the user necessarily doing anything to the notification). To support this mode, you are supposed to implement the -application:didReceiveRemoteNotification:fetchCompletionHandler: method.
The documentation for -application:didReceiveRemoteNotification: says that if your application delegate implements the application:didReceiveRemoteNotification:fetchCompletionHandler: method, then "the app object calls that method instead of this one." Which means we cannot use -application:didReceiveRemoteNotification: to handle remote notifications anymore, since it's not going to be called.
We should probably put handling logic in application:didReceiveRemoteNotification:fetchCompletionHandler:, but the previous trick for handling it doesn't make sense anymore -- previously, we depended on the fact that the only way for -application:didReceiveRemoteNotification: to be called when the app is not active was if the user tapped the action button on the notification to open the app. However, now, the whole point of the remote-notification background mode is that it can call application:didReceiveRemoteNotification:fetchCompletionHandler: in the background every time a remote notification is received, before the user does anything to it.
So then, how can we now tell when the user opens the app using the action button on the notification?
You still check the application state in application:didReceiveRemoteNotification:fetchCompletionHandler:
UIApplicationStateBackground - App is in the background receiving a push notification
UIApplicationStateInactive - App is opening from the user tapping a notification
I was use this delegate function to add the 『Notification Number』.
Cause our Server not send the Badge to our Clients.
Then I used the strange method to add the 『Notification Number』 with this delegate function, and I also add a code to switch UIViewController in this function.
I found out when I use the server push Notification to my test App, and the status of test App is in the background, even I am using Twitter or Safari.
My test App also switch UIViewController to another UIViewController after I push Notification from the server.

IOS Is there a way to send user to particular view after tapping "view" on notification?

I am using push notifications in my app and I would like to send user to particular view, not the view he last saw. Is it possible?
You need to implement the appropriate AppDelegate messages.
Specifically, you will receive the APNS payload on the application:didFinishLaunchingWithOptions:
You might also receive the payload in a different message, application:didReceiveRemoteNotification: if the application is active.
Then when you know that your app was launched because the user touched a notification, you can direct him to a specific view accordingly.
I don't think that you have control over what the user sees while app is starting app (opening animation). After the app is fully active, you can send him wherever you want to by opening proper view controllers, setting proper tab, etc...

Resources