Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

codename one local notifications not working on ios

I have added a local notifications so when my app gets a push while opening there is still a popup and a sound. It's working fine on Android, but on iOS the local notification doesn't appear at all.

The push notifications are working fine on both platforms.

This is my code in the push callback that should trigger the notification (if the app 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);
}
like image 585
peopletookallthegoodnames Avatar asked Feb 22 '16 21:02

peopletookallthegoodnames


2 Answers

Local notifications don't fire while the app is open in the foreground. You should use a different mechanism to make a sound while the app is running. Eg Display.vibrate()

like image 66
steve hannah Avatar answered Sep 28 '22 06:09

steve hannah


- (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
 ]; 
like image 44
kalpesh satasiya Avatar answered Sep 28 '22 07:09

kalpesh satasiya