类型 库 版本 版本 2024.3703 关键词 通知 平台 Android、iOS
提供对本地和推送通知的访问。
local notifications = require( "plugin.notifications" )
要使用此插件,请在 `build.settings` 的 `plugins` 表中添加一个条目。添加后,构建服务器将在构建阶段集成该插件。
settings = { plugins = { ["plugin.notifications"] = { publisherId = "com.coronalabs" }, }, }
如果您的应用适用于 Android,并且您打算使用 GCM 推送通知,则还需要包含以下插件。但是,如果您只打算使用本地通知,则应省略此插件。
settings = { plugins = { ["shared.google.play.services.gcm"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true } }, }, }
此外,请在您的 `config.lua` 文件中添加一个 `notification` 表,如下所示。当您向 GCM 服务注册时,您应该收到 `google` 表所需的 `projectNumber` 值。
application = { notification = { google = { projectNumber = "YOUR_PROJECT_NUMBER" }, } }
如果您正在将 Solar2D Native 用于 iOS,则需要在您的 `Info.plist` 中添加对 `CoronaNotificationsDelegate` 的引用,如下所示
在您的 `Info.plist` 中添加一个名为 `CoronaDelegates` 的条目,并将其类型设置为 `Array`。
向 `CoronaDelegates` 数组添加一个条目,并将其命名为 `CoronaNotificationsDelegate`。确保其类型为 `String`。