-
Notifications
You must be signed in to change notification settings - Fork 0
Runtime APIs
hp-sam edited this page Dec 9, 2014
·
3 revisions
--Device Events
DEVICE_SHAKE = "Shake"
PUSH_TOKEN_UPDATED = "PushTokenUpdated"
PUSH_NOTIFICATION = "PushNotification"
HANDLE_OPEN_URL = "HandleOpenURL"
OnBackground = "OnBackground"
OnForeground = "OnForeground"
NETWORK_TYPE_CHANGED = "NetworkTypeChanged"
--FW Events
FW_HTTP_403_3_1 = "FW_HTTP_403_3_1"
FW_HTTP_403_2_2 = "FW_HTTP_403_2_2"Sample Code (Listen for Device Shake Event):
local Event = require "framework.event"
Event.gbind(Event.DEVICE_SHAKE, function(e)
print(e)
end)
-- Lua 5.2
Event.gbind(Event.DEVICE_SHAKE, function(e)
print(e)
end, _ENV)Sample Code (Monitor background/foreground):
local Event = require "framework.event"
Event.gbind("OnBackground", function()
print("OnBackgroundOnBackground")
end)
Event.gbind("OnForeground", function()
print("OnForegroundOnForeground")
end)
-- Lua 5.2
Event.gbind("OnBackground", function()
print("OnBackgroundOnBackground")
end, _ENV)
Event.gbind("OnForeground", function()
print("OnForegroundOnForeground")
end, _ENV)
local deviceservice = registry.getService("device")
for k,v in pairs(deviceservice) do
print(k,v)
end
while true do
print(deviceservice.batteryLevel) -- [16:18:27.236] 0.89999997615814
print(deviceservice.wlan) -- [16:18:27.242] true
print(deviceservice.userAgent) -- [16:18:27.243] Mozilla/5.0 (iPhone; CPU iPhone OS 7_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D167 MaryKayMobility/1.2.0
deviceservice.flashlight = not deviceservice.flashlight
deviceservice.statusBarHidden = not deviceservice.statusBarHidden
deviceservice:vibrate()
sleep(5)
deviceservice:playSoundFile("tap.aif")
sleep(5)
end
--[[
[16:18:27.223] os.version 7.1
[16:18:27.224] modelId iPhone4,1
[16:18:27.224] framework.version 1.2.0
[16:18:27.224] locale zh_CN
[16:18:27.224] macaddress 02:00:00:00:00:00
[16:18:27.224] manufacturer Apple
[16:18:27.224] language zh-Hans
[16:18:27.225] identifier A27997B2-9B8D-46C8-BEDD-825017A58A72
[16:18:27.225] __id__ userdata: 0x165f9854
[16:18:27.225] os.name IOS
[16:18:27.225] retina true
[16:18:27.225] uuid A27997B2-9B8D-46C8-BEDD-825017A58A72
[16:18:27.225] type Mobile
[16:18:27.225] model iPhone 4S
[16:18:27.225] resolutionHeight 460
[16:18:27.226] resolutionWidth 320
[16:18:27.226] networkType WCDMA
[16:18:27.226] framework.name com.marykay.china.mobilityApp
[16:18:27.236] 0.89999997615814
[16:18:27.242] true
[16:18:27.243] Mozilla/5.0 (iPhone; CPU iPhone OS 7_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D167 MaryKayMobility/1.2.0
]] local localnotificationservice = registry.getService("localnotification")
localnotificationservice:clear() -- remove all if required.
localnotificationservice:add{
sound = localnotificationservice.defaultSound,
title = "You have a new message.",
action = "ClickMe",
datetime = os.time() + 10, -- 10s later
body = {id = "0001"} -- any table map.
}
local Event = require "framework.event"
local json = require "json"
Event.gbind(Event.PUSH_NOTIFICATION, function(e)
print(json.encode(e.body))
end)| name | description |
| add(url:string):DownloadInfo | add a url to the download service, and return the download info object. |
| add(url:string, cachekey:string):DownloadInfo | add a url to the download service, and return the download info object. |
| query(infoid:string):DownloadInfo | query the download info object by info id |
| delete(infoid:string):boolean | cancel download task by info id, and remove everything. |
| pause(infoid:string):DownloadInfo | pause task by info id and return download info |
| resume(infoid:string):DownloadInfo | resume task by info id and return download info |
| stop(infoid:string):DownloadInfo | stop task by info id and return download info |
| pauseAll() | pause all tasks |
| resumeAll() | resume all tasks |
| stopAll() | stop all tasks |
| name | description |
| installFile(filePath:string, appId:string):boolean | install app from local path (path from downloadinfo) |
| installURL(url:string, appId:string):boolean | install app from remote url |
| scan() | refresh installed apps |
| remove(appId:string, withData:boolean = false):boolean | remove app, if not removeAll, app data will not be removed. |
| list(category:string):EOSList | list apps by category |
| pathForApp(appId:string):string | return app's absolute path by appId |
| getAppSandbox(appId:string):AppSandbox | return the sandbox by appId |
| getPageSandbox(appId:string, pageId:string = nil):PageSandbox | get page sandbox by appId and pageId, if pageId was not set, return the page sandbox of the default page. |
| name | description |
| preview(path:string):void | preview document. |
| name | description |
| addLocationWatcher(func:LuaFunction):LuaFunctionWatcher | add location watcher, will be called when location changes. callback(location:LuaLocation) |
| addHeadingWatcher(func:LuaFunction):LuaFunctionWatcher | add heading watcher, will be called when heading changes. callback(heading:LuaHeading) |
| start():boolean | start location service |
| stop():boolean | stop location service |
| newLocation(latitude:float,longitude:float):LuaLocation | create a new LuaLocation Object |
| name | description |
| load(func:LuaFunction):void | load contacts, func will be invoked on complete |
| addChangeWatcher(func:LuaFunction):LuaFunctionWatcher | func will be invoked on contacts changes. |
| getAll():List | get all contacts List, item in list: LuaRecord |
| name | description |
| load(filePath):LuaImage | load image from file. |
| name | description |
| load(func:LuaFunction):void | load photos, func will be invoked on complete |
[sqlcipher](http://sqlcipher.net/sqlcipher-api/)
[lua sqlite3](http://lua.sqlite.org/index.cgi/doc/tip/doc/lsqlite3.wiki)
local utils = require "framework.utils"
local base = require "framework.base"
local Event = require "framework.event"
Event.gbind(Event.PUSH_TOKEN_UPDATED, function(e)
print(e.token) -- nil on fail
end)
Event.gbind(Event.PUSH_NOTIFICATION, function(e)
print(e.alert, e.badge, e.body)
print(base.getGSandbox():get("notification_data")) -- any place you want after app launch.
base.getGSandbox():put("notification_data", nil) -- clear data
end)
utils.requestPushToken()