Clear All UILocalNotification from Notification Drawer in iOS9 using ObjectiveC - uilocalnotification

In my application i am firing alarm notification, if user ignores that
then after user launch application at this time i want to clear all
the notification from notification drawer which are fired and not yet
seen or tapped.
How can i achieve this?
tried:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
but its cancelling the future local notifications.

Related

OS X XMPP logout Chat Application using xcode 6.4

I am developing chat application in os x with XMPP framework, where there is main chat viewcontroller with chat view but when user clicks logout button i navigate user to login viewcontroller by calling offline method,xmpp disconnect method and self window close. After this during re-login xmpp connection is not happening.
code used :
-(void)logout
{
[self goOffline];
[self xmppStreamDidDisconnect:xmppStream withError:nil];
ViewController *bcktologin =[self.storyboard instantiateControllerWithIdentifier:#"ViewController"];
[self presentViewControllerAsModalWindow:bcktologin];
[self dismissViewController:self];
[self.view.window close];
}
so after this:
My chat controller keeps running behind, menu created in it is no removed.
No connection to XMPP after re-login
Please guide.

Strange behavior of registerUserNotificationSettings in iOS8

I try to register only alert type notification at application start in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
by calling
UIUserNotificationType types = UIUserNotificationTypeAlert;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
In
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
I permanently get all types in notificationSettings
<UIUserNotificationSettings: 0x16dd6160; types: (UIUserNotificationTypeAlert UIUserNotificationTypeBadge UIUserNotificationTypeSound);>
And
UIUserNotificationSettings *settings = [[UIApplication sharedApplication] currentUserNotificationSettings]
gives me the same all types despite my initial choice of the only alert type.
So I can't setup restricted dynamical permissions on start.
There is no any information about similar problems in the internet.
It seems that it is impossible to setup UserNotificationType from application in iOS8 (at least). One needs to use general Notification Center to set any combination of sound, badge and alert. Only the first attempt to register which occurs with Push notification permissions alert sets UserNotificationType needed.
Another way is to send UserNotificationType on subscription to your push server which should make payload depending of this type.
You must register notifications in (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
UPDATE:
According to the Apple documentation:
The first time you call the registerUserNotificationSettings: method,
iOS presents a dialog that asks the user for permission to present the
types of notifications the app registered. After the user replies, iOS
asynchronously calls back to the UIApplicationDelegate object with the
application:didRegisterUserNotificationSettings: method, passing a
UIUserNotificationType object that specifies the types of
notifications the user allows.
Users can change their notification settings at any time using the
Settings app. Your app is added to the Settings app as soon as you
call registerUserNotificationSettings:. Users can enable or disable
notifications, as well as modify where and how notifications are
presented. Because the user can change their initial setting at any
time, call currentUserNotificationSettings before you do any work
preparing a notification for presentation
So if user has already accepted Notification settings, application can't change them. currentUserNotificationSettings always show current user settings, not application settings.

IOS Targeted Push Notification - Parse API

I'am implementing a solution to allow the user to receive push notifications only from the list of users he is following. I read about advanced targeting recipients when pushing messages. How should I setup up my installation object in order to receive posts only from the users I’m following. Should I fetch the list of users he is following and setup the installation object. The issue is, I’m using Parse login view controller and I’ll get the list of users I’am following, only after I login. My second question is if the user will be able to get the push notifications if he is not logged in. My third question, is a new Parse installation object is created every time the app is launched? The requirement is I should see push notification from users I'am following. Please advise.
I have had similar questions and concerns while implementing my own authentication and push alert system. This is how I handled it.
in AppDelegate.m:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
if (authenticated) {
NSString *user = someUniqueStringForUser;
[currentInstallation addUniqueObject:user forKey:#"channels"];
}
[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
NSLog(#"Successful Registration %s", __PRETTY_FUNCTION__);
} else {
NSLog(#"Error %#, %s", error, __PRETTY_FUNCTION__);
}
}];
}
In your login ViewController.m
- (void)authenticatedAndRegisterForPush {
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)];
NSString *appUser = uniqueString;
[currentInstallation addUniqueObject:appUser forKey:#"channels"];
[currentInstallation saveInBackground];
}
I'm not 100% sure you'll need to add channels again since the didRegister method handles the logic, but I'm doing it and it seems to be working correctly. Then in whatever view controller you have to select people to follow you just call the PFInstallation object, subscribe it to channels, and save.
When you want to send push notifications, you'll send it to all people who are subscribed to those channels. Parse will fail to send a push notification if there is no device token information registered to the installation.
I believe there are some minor changes to remote/push notifications in iOS 8, so if you're building against the iOS SDK there may be minimal changes to the appDelegate methods.
If you want to remove push notifications for a user you'll have to do the opposite of the registration process. Call the installation, remove all channels it'll listen to, and then save.
To my understanding, PFInstallation looks to see if there is an installation instance related to the appBundle. So if you were to log out and log back in, it recognizes the device and installation as the same. I've only had issues with logging out and push notifications only if I didn't clean out the channels correctly. There is also a pain with testing when deleting and re-installing on the same device creating multiple installations. I haven't found a great solution to this particular problem, but if you do please let me know.
Hope that helps.

Post notification using NSDistributionCenter in sandboxed apps

I am looking at ways on sending message from my main app to helper app. Its just a one way communication. I came accross XPC, unix sockets and NSDistributioncenter and found that posting notifications was the simplest one.
I am using postNotificationName:object: to send notifications.
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:#"aNote"
object:#"Hello"];
In helper app I have added observers in applicationDidFinishLaunching to receive notifications.
[[NSDistributedNotificationCenter defaultCenter] addObserver:self
selector:#selector(hello:)
name:#"aNote"
object:nil];
But it can only get notified if sandboxing is turned off. In the Apple docs it does say that userInfo must be nil if app is sandboxed but I am not using userInfo. I also tried with postNotificationName:object:userInfo: with userInfo nil but still it didnt work.
How can I get this to work in Sandboxed apps ?

Control the apple notification click when the initiator programm is not running

My product works as following:
My application opens notification
My application exits
Now, when the user clicks the notification, my application is opened again. I DONT WANT it. I want that if user clicks the notification - it will just disappear
I found there is a callback for that (and it works)
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification
{
[center removeDeliveredNotification: notification];
}
but it works only when my application is running.
Is it possible to implement the behavior I want at all?
No it isn't possible to avoid having your application launched when a user touches your notification.
The application will always be launched in response to touching a notification and the UIApplicationDelegate method application:willFinishLaunchingWithOptions: will always be called when the application is not running.
Your app doesn't have to action on the notification, but it will be launched.

Resources