【发布时间】:2014-10-23 20:41:43
【问题描述】:
我正在尝试使用 Corona 运行默认的 pubnub Helloworld 示例。 corona sdk 程序在模拟器中运行良好,但由于某种原因我在 pubnub 控制台中看不到输出。这是 pubnub Corona SDK 的源代码。
require "pubnub"
multiplayer = pubnub.new({
publish_key = "my_publish_key",
subscribe_key = "my_subscribe_key",
secret_key = nil,
ssl = nil,
origin = "pubsub.pubnub.com"
})
multiplayer:subscribe({
channel = "hello-world-corona",
callback = function(message)
print(message.msgtext)
end,
errorback = function()
print("Oh no!!! Dropped 3G Conection!")
end
})
function send_a_message(text)
multiplayer:publish({
channel = "hello-world-corona",
message = { msgtext = text }
})
end
function send_hello_world()
send_a_message("Hello World!!!")
end
timer.performWithDelay( 500, send_hello_world, 10 )
send_hello_world()
我正在使用 pubnub 提供的订阅和发布密钥
为了创建 API 密钥,我使用了 pubnub 中的这些库: https://github.com/pubnub/lua
问题是,当我为 Android 构建 APK 并运行它时,我无法在 http://www.pubsub.com/console 的 pubsub 控制台上看到消息。我使用给定的订阅和发布密钥,但什么也没看到。我收到了 Internet 权限的运行时错误,但随后将我的 build.settings 更改为以下内容,不再出现运行时错误:
build.settings:
settings =
{
android =
{
permissions =
{
{ name = ".permission.C2D_MESSAGE", protectionLevel = "signature" },
},
usesPermissions =
{
-- Required by the MapView to fetch its contents from the Google Maps
--servers.
"android.permission.INTERNET",
"android.permission.GET_ACCOUNTS",
"android.permission.RECEIVE_BOOT_COMPLETED",
"com.google.android.c2dm.permission.RECEIVE",
".permission.C2D_MESSAGE",
-- Optional permission used to display current location via the GPS.
"android.permission.ACCESS_FINE_LOCATION",
-- Optional permission used to display current location via WiFi or
-- cellular
-- service.
"android.permission.ACCESS_COARSE_LOCATION",
},
usesFeatures =
{
-- If you set permissions "ACCESS_FINE_LOCATION" and
--"ACCESS_COARSE_LOCATION" above, then you may want to set up
--your app to not require location services as follows.
-- Otherwise, devices that do not have location sevices (such as a GPS) will
-- be unable
-- to purchase this app in the app store.
{ name = "android.hardware.location", required = false },
{ name = "android.hardware.location.gps", required = false },
{ name = "android.hardware.location.network", required = false },
},
},
}
【问题讨论】:
-
注意,从 Corona 模拟器运行时我也看不到消息。不确定我应该可以吗?