【问题标题】:Cancel an iOS scheduled LocalNotification using id (Titanium)使用 id (Titanium) 取消 iOS 计划的 LocalNotification
【发布时间】:2013-05-28 21:01:17
【问题描述】:

我使用的是 Titanium SDK 3.1。我想取消预定的 LocalNotification (iOS)。我看到了Ti.App.iOS.cancelLocalNotification(Number id) (http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.App.iOS) 方法,但我不知道在创建Ti.App.iOS.scheduleLocalNotification(<NotificationParams>) 时如何指定id。我读到我必须在 userInfo 属性内创建一个名为 id 的属性,但我无法让它工作。

示例代码(不起作用):

Ti.App.iOS.scheduleLocalNotification({
    alertBody : "My notification",
    badge : 0,
    repeat : "daily",
    userInfo : {
         id : 1234
    },
    sound : "alarm.mp3",
    date : new Date()
});

Ti.App.iOS.cancelLocalNotification(1234); // => undefined

【问题讨论】:

    标签: javascript ios notifications titanium uilocalnotification


    【解决方案1】:

    尝试更新代码如下

    Ti.App.iOS.scheduleLocalNotification({
        alertBody : "My notification",
        badge : 0,
        repeat : "daily",
        userInfo : {
             "id" : 1234
        },
        sound : "alarm.mp3",
        date : new Date()
    });
    
    Ti.App.iOS.cancelLocalNotification(1234);
    

    我已在您的代码中更新了对象 userInfo,因为 userInfo 是字典类型。

    来自Appcelerator docs 类型 Dictionary 用于描述使用的普通 JavaScript 对象 传递一组属性

    您可以参考以下链接了解更多关于取消本地通知的信息。

    1. Remove Specific Local Notifications in iOS

    2. Using Local Notifications in Titanium

    【讨论】:

    • 我尝试了代码,现在它似乎工作正常,但Ti.App.iOS.cancelLocalNotification(id) 返回undefined。正常吗?
    • @JMasip:cancelLocalNotification() 方法返回 void。请参考docs.appcelerator.com/titanium/latest/#!/api/…了解更多信息,如果我的回答解决了您的问题,请打勾
    猜你喜欢
    • 1970-01-01
    • 2012-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    • 2011-11-10
    • 1970-01-01
    相关资源
    最近更新 更多