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.
Related
In doing some testing on the iOS 11 preview, I've noticed that when I get push notifications while my app is foregrounded the OS displays the system notification that you normally only see when your app is not active.
I didn't see anything announced as having been changed, or any new APIs to change this behavior one way or another. Does anyone know or have links to documentation stating if this is intended, a bug, temporary, or what?
There's an option for showing Push Notifications in the foreground in UserNotification framework.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
Quoting the comment from the Framework:
The method will be called on the delegate only if the application is in the foreground. If the method is not implemented or the handler is not called in a timely manner then the notification will not be presented. The application can choose to have the notification presented as a sound, badge, alert and/or in the notification list. This decision should be based on whether the information in the notification is otherwise visible to the user.
This could be the place to start looking for the answer.
I'm building an iOS game using Google Play Game for turn-based multiplayer but cannot receive any notifications. I did research many days to find what is wrong but i can't find anything.
So is iOS push notification in Google Play game still working at this time? Do your games still receive push notifications normally? Please provide me some information.
Thank you!
It is still indicated in the documentation that invitation and turn notifications are currently supported on Android and iOS. Based from this tutorial, you need to register your app to receive push notifications.
In your appDelegate, add the following code to the callback for retrieving the push device token passed back from APNS. This device token is used for outbound push notifications, and your app must register it with the Google Play games services push service. Make sure to always register your device token through GPGManager to enable push notifications from Google Play games services. Even if the user has not signed in; the GPGmanager object will cache this token and save it until the user signs in.
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken
:(NSData *)deviceToken {
NSLog(#"Got deviceToken from APNS! %#", deviceToken);
[[GPGManager sharedInstance] registerDeviceToken:deviceToken
forEnvironment:GPGPushNotificationEnvironmentSandbox];
}
From this related thread:
If you are having issues you might want to make sure the token is being registered correctly with APNS in the AppController.m (by logging it).
Also, there are two certificates you can register on the Play console, one for sandbox and one for production. Make sure that certificate you are using is the one being configured. By default the AppController calls
gpg::RegisterDeviceToken(deviceToken, false); which indicates that this is the prod certificate configured on the console.
You can also check this related GitHub issue which might help.
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.
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.
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.