Corona,system.scheduleNotification不能正常工作。

我正在尝试实现一个本地通知系统的应用程序。该系统应取消一些不必要的通知。system.scheduleNotification 的功能很好(它创建了通知并且它们工作正常),但它返回 nil(它应该返回 ID)。因此,我无法通过通知 ID 取消任何通知。

实际上,我使用的代码非常简单。任何帮助都将有所帮助...

local nextRefreshTime = 60 -- 不总是60,只是个示例
local options = {
    alert = "此处有一些文本。",
    badge = ( native.getProperty( "applicationIconBadgeNumber" ) or 0 ) + 1,
}

notifications[#notifications+1] = system.scheduleNotification( nextRefreshTime, options )
print(notifications[#notifications]) -- 输出 nil!?!
-- 另一个示例(测试)
print( system.scheduleNotification( nextRefreshTime, options ) ) -- 也输出 nil!?!

p.s:我还尝试使用 utcTime 参数调用 system.scheduleNotification

点赞
用户825481
用户825481

你没有发布你的全部代码,所以我不知道你的代码在做什么。确保在选项中你的警报是一个字符串。应该长这样:

local options = {
    alert = "Wake up!",
    badge = 2,
}

请记住,你的代码是在说你的系统通知将1添加到通知表中。现在 system.scheduleNotification 不是一个 string,它是一个表,所以当你尝试 print(notifications[#notification]) 时,它会打印 nil 是有道理的。我认为你必须打印出 notification[alert],但我不确定。请查看这个链接:http://lua-users.org/wiki/TablesTutorial

2013-12-12 21:17:46
用户1979583
用户1979583

你正在为corona模拟器构建应用程序吗?那么它不会起作用。请为Xcode模拟器构建它以测试本地通知。从corona示例代码中获取的示例项目输出图像如下所示:

enter image description here

代码如下:

local options = {
   alert = "Wake up!",
   badge = 1,
   sound = "alarm.caf",
   custom = { msg = "bar" }
}

notificationID = system.scheduleNotification( time, options )

local displayText = "Notification using Time: " .. tostring( notificationID )
print( displayText ) -- It will print the user data

继续编码……:)

2013-12-18 14:13:46