【问题标题】:Robovm Local notifications not showing up. Scheduling seems successful. Am I missing something?Robovm 本地通知未显示。调度似乎成功了。我错过了什么吗?
【发布时间】:2015-12-31 05:09:11
【问题描述】:

我正在尝试使本地/预定通知正常工作。随着推送消息(使用 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();

【问题讨论】:

    标签: java ios libgdx robovm


    【解决方案1】:

    添加后问题解决:

    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);
    

    【讨论】:

    • 您介意分享代码吗?我正在尝试生成通知,但它对我不起作用。
    • 我添加了我的工作代码的 sn-p。虽然它已经主要在 OP 中了
    猜你喜欢
    • 2010-11-26
    • 1970-01-01
    • 1970-01-01
    • 2022-01-05
    • 2010-11-03
    • 1970-01-01
    • 2020-09-21
    • 1970-01-01
    • 2018-01-05
    相关资源
    最近更新 更多