Codename of one local notification not working on ios

I added local notifications, so when my application receives a click during opening, a popup and sound still appear. It works fine on Android, but on iOS, a local notification does not appear at all.

Push notifications work great on both platforms.

This is my code in a push callback that should trigger a notification (if the application is open):

if(Display.getInstance().getCurrent() != null) { LocalNotification n = new LocalNotification(); n.setId(value); n.setAlertBody(value); n.setAlertTitle({app name}); n.setBadgeNumber(1); Display.getInstance().scheduleLocalNotification(n, System.currentTimeMillis() + 1000, LocalNotification.REPEAT_NONE); } 
+5
source share
4 answers

Local notifications do not start while the application is open in the foreground. You must use a different mechanism to create sound while the application is running. For example, Display.vibrate ()

+3
source
 - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo { [[NSNotificationCenter defaultCenter] postNotificationName:@"DriverNotification" object:nil userInfo:userInfo]; // [[NSNotificationCenter defaultCenter] postNotificationName:@"UserNotification" object:nil userInfo:userInfo]; NSLog(@"%@",userInfo); } 

Put this code in your view controller

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNotification:) name:@"DriverNotification" object:nil ]; 
+1
source

Did you call registerUserNotificationSettings to register the fact that your application uses local notifications? If you do not, your request to publish a local notification will be ignored.

See this text from the description of this method:

If your application displays alerts, plays sounds or icons on the icon, you must call this method during the startup cycle to request permission to alert the user this way. (You should also make this request if you want to set the applicationIconBadgeNumber property directly.) Typically, you make this request if your application uses local or remote notifications to alert the user about new information related to your application. The first time the application starts and calls this method, the system asks the user if your application is allowed to deliver notifications and saves the response. After that, the system uses the saved response to determine the actual types of notifications that you can use.

After calling this method, the application calls application: didRegisterUserNotificationSettings: its application method to the delegate to report the results. You can use this method to determine if your request was submitted or rejected by the user.

It is recommended that you use this method before planning for local notifications or registering with the push notification service. Calling this method using a new custom settings object replaces the previous settings request. Applications that support custom actions must include all of their supported actions in the notificationSettings object.

0
source

you need to add below code in didFinishLaunchingWithOptions file of AppDelegate.m file to register local notification

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) { [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; [[UIApplication sharedApplication] registerForRemoteNotifications]; } else { [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)]; } } 
0
source

Source: https://habr.com/ru/post/1243611/


All Articles