Robovm本地通知未显示。调度似乎很成功。我错过了什么吗?

时间:2015-12-31 05:09:11

标签: java ios libgdx robovm

我正在努力让本地/预定通知正常工作。使用推送消息(使用Parse)工作正常我虽然本地很容易,但即使注册似乎很好(didRegisterUserNotificationSettings被触发)并且调度似乎也有效,通知也不会显示。我已经在iOS 7(iphone 4)和iOS 9(iphone模拟器)上进行了测试。我错过了什么?

这是我的代码:

@Override
public boolean didFinishLaunching(UIApplication application,UIApplicationLaunchOptions launchOptions)    
{
 boolean retval = super.didFinishLaunching(application, launchOptions);
 //some other stuff happens here regarding parse push. But since this works I have cut it out
 registerForPush();
 return retval;

}


public void registerForPush()
{
 if (IOSLauncher.getOSMajorVersion() >= 8)
 {
 UIUserNotificationType userNotificationTypes = UIUserNotificationType.with(UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound);


 UIUserNotificationSettings settings = new UIUserNotificationSettings(userNotificationTypes, null);
 application.registerUserNotificationSettings(settings);
 application.registerForRemoteNotifications();
 }
 else
 {
 UIRemoteNotificationType type = UIRemoteNotificationType.with(UIRemoteNotificationType.Alert, UIRemoteNotificationType.Badge, UIRemoteNotificationType.Sound);
 application.registerForRemoteNotificationTypes(type);
 }
}


public void scheduleNotification(String title, String text, Date date, int ID)
{
    UILocalNotification notification = new UILocalNotification();
    if(getOSMajorVersion() >= 8 && getOSMinorVersion() >= 2)
    notification.setAlertTitle(title);
    notification.setAlertBody(text);
    notification.setFireDate(new NSDate(date));
 NSMutableDictionary<NSObject, NSObject> dict = new NSMutableDictionary<>();
 dict.put("id",NSNumber.valueOf(ID));
 notification.setUserInfo(dict);
    UIApplication.getSharedApplication().scheduleLocalNotification(notification);
}

编辑: 在确定通知后,它将出现在由以下字符返回的数组中:

UIApplication.getSharedApplication.getScheduledLocalNotifications();

1 个答案:

答案 0 :(得分:0)

添加:

后问题得以解决
notification.setTimeZone(NSTimeZone.getLocalTimeZone());

并将我的测试计时器的过期时间设置为1分钟到5分钟 我不确定哪个是实际的解决方案,但问题已经消失,所以我很高兴!

编辑:

UILocalNotification notification = new UILocalNotification();
notification.setAlertTitle("title");
notification.setAlertBody("text");

NSMutableDictionary<NSObject, NSObject> dict = new NSMutableDictionary<>();
//add any customer stuff to your dictionary here
notification.setUserInfo(dict);
notification.setFireDate(new NSDate(date));         //date is some date in the future. Make sure it is in the correct TZ. If it does not work, try to make it at least 5 minutes in the future. I remember this helping my situation
notification.setTimeZone(NSTimeZone.getLocalTimeZone());
UIApplication.getSharedApplication().scheduleLocalNotification(notification);