native.newWebView( )

Loads a remote web page in a webView container. Native webViews differ from web popups in that you can move them (via x/y properties), rotate them (via rotation property), and assign physics bodies to them (in the same manner you would any other display objects.

This API supports loading from either a local file containing HTML content (in one of the System directories) or from a remote website.

Syntax: 

object = native.newWebView( left, top, width, height )

Example: 

local webView = native.newWebView( 0, 0, 320, 480 )
webView:request( "http://www.anscamobile.com/" )
-- or
webView:request( "localfile.html", system.ResourceDirectory )

This example prints the url and/or errorCode in the callback listener:

local function webListener( event )
    if event.url then
        print( "You are visiting: " .. event.url )
    end
 
    if event.type then
        print( "The event.type is " .. event.type  -- print the type of request
    end
 
    if event.errorCode then
        native.showAlert( "Error!", event.errorMessage, { "OK" } )
    end
end
 
local webView = native.newWebView( 0, 0, 320, 480, webListener )
webView:request( "http://www.anscamobile.com/" )
 
webView:addEventListener( "urlRequest", webListener )
. . .
-- remove the webView as with any other display object
webView:removeSelf()
webView = nil

Parameters: 

left, top
numbers. The left/top starting position of the web view.

width, height
numbers. The width/height of the webView object (in pixels).

Methods

Note: The "webView" listed below corresponds to the webView object returned from calling native.newWebView().

webView:request( url [, baseDir] )
Loads specified url (string) into webView. For local content, you MUST specify a base directory as a search path (see: System-defined Directories).

webView:stop()
Stops loading current page in webView (if loading).

webView:reload()
Reloads currently loaded page in webView.

The following methods require build 2012.736 or higher:

webView:back()
Takes the webView back one step in the webView's history.

webView:forward()
Takes the webView forward one step in the webView's history.

Properties

x, y
numbers. Represents the x/y position of the webView after it has been created. You may move the webView by changing these properties.

rotation
number. You may rotate the webView object by changing this value (0-360).

hasBackground
boolean (true/false). This is a get/set property that corresponds to whether or not the background of the webView is visible or transparent.

The following properties require build 2012.736 or higher:

canGoBack
boolean (true/false). Read-only property that will be true if webView can go back a webpage, and false if not.

canGoForward
boolean (true/false). Read-only property that will be true if webView can go forward a webpage, and false if not.

Listener

You can add an optional callback listener using
object:addEventListener( "urlRequest", listener )

This callback occurs when the URL is requested (shouldLoad method) and before the loading of the requested URL has started. The listener will be called for all URL loads, including the initial "request". It will also be called if other URLs are requested from the website (e.g., twitter, facebook, ads, etc.).

The listener callback includes the URL being requested (event.url), an error code (event.errorCode), an error message (event.errorMessage), and event type (event.type). Error codes and messages are only present if there was an error with the request.

event.type is the type of URL request being made: "link", "history", "form", "formResubmit", "reload", and "other". This may also be nil if the platform doesn't support this property. (Currently, it's only available on iOS.)

The main difference between the webView listener and web popup listeners is that returning true/false has no effect (with web popups, returning false in the listener would cause the web popup to close).

Returns: 

Native webView object. This API supports multiple webView objects.

Supported on:
Mac OS X: 
--
Windows: 
--
iOS: 
2012.730
Android: 
--
Remarks: 

Some methods and properties require build 2012.736 or higher.

event.name

For network reachability events this property is set to "networkStatus".

Syntax: 

value = event.name

Example: 

function MyNetworkReachabilityListener(event)
        print( "name", event.name )
        print( "address", event.address )
        print( "isReachable", event.isReachable )
        print("isConnectionRequired", event.isConnectionRequired)
        print("isConnectionOnDemand", event.isConnectionOnDemand)
        print("IsInteractionRequired", event.isInteractionRequired)
        print("IsReachableViaCellular", event.isReachableViaCellular)
        print("IsReachableViaWiFi", event.isReachableViaWiFi)   
end
 
if network.canDetectNetworkStatusChanges then
        network.setStatusListener( "www.apple.com", MyNetworkReachabilityListener )
else
        print("network reachability not supported on this platform")
end

Parameters: 

None.

Returns: 

string
Returns name of event, "networkStatus".

Supported on:
Mac OS X: 
build 2011.496
Windows: 
--
iOS: 
build 2011.496
Android: 
--

gameNetwork.request()

Send or request information to/from the game network provider.

Syntax: 

gameNetwork.request( command [, parms ...] )

Example: 

local gameNetwork = require "gameNetwork"
 
--For OpenFeint:
gameNetwork.init( "openfeint", "product-key", "secret", "display name", "appId" )
 
gameNetwork.request( "setHighScore", { leaderboardID="abc123", score=99, displayText="99 sec" } )
gameNetwork.request( "unlockAchievement", "achievementId" )
gameNetwork.request( "uploadBlob", key, data )
gameNetwork.request( "downloadBlob", key, listener ) -- listener for "completion" event with "blob" key set.
gameNetwork.show( "highscore", "abc123" )

local gameNetwork = require "gameNetwork"
 
--For Papaya (Android only):
gameNetwork.init( "papaya", "papayaSocialKey" )
 
gameNetwork.request( "setHighScore", { leaderboardID = "Level1", score = 321 } )
gameNetwork.request( "unlockAchievement", " 184 " )

local gameNetwork = require "gameNetwork"
 
--For Game Center (iOS only):
gameNetwork.init( "gamecenter", {listener=initCallback} )
 
gameNetwork.request( "setHighScore",
{
    localPlayerScore = { category="com.appledts.EasyTapList", value=25 },
    listener=requestCallback
})
gameNetwork.request( "resetAchievements", { listener=requestCallback } )

Parameters: 

command

OpenFeint

Strings supported by the OpenFeint provider:

  • setHighScore
  • unlockAchievement
  • uploadBlob: (Not supported on Android)
  • downloadBlob (Not supported on Android)

parms

Parmeters used in the above OpenFeint commands:

setHighScore: { leaderboardID="abc123", score=99 [, displayText="99 sec"] }
Note: Starting with Build 2012.815, for Game Center compatibility, 'category' may be used instead of 'leaderboardID' and 'value' may be used instead of 'score'.
unlockAchievement: "achievementId"
uploadBlob: "uploadBlob", key, data
downloadBlob: key, [listener] ) -- listener for "completion" event with "blob" key set.

The optional Listener for downloadBlob that is called when the "blob" string has been downloaded:

  • event.name -- The name of the event, "completion".
  • event.data or event.blob -- A string that contains the requested blob data. If the length of this string is 0, then the download failed. Note: In Build 2012.725, event.data was introduced as a universal generic field holding the return data. event.data and event.blob are references to the same data. Also note that starting in Build 2012.725, the event.name no longer returns "completion", but instead returns "gameNetwork" along with additional common fields for all gameNetwork event types. c

Papaya (Android)

Strings supported by the Papaya provider:

  • setHighScore
  • unlockAchievement

parms

Parmeters used in the above Papaya commands:

setHighScore: { leaderboardID="abc123", score=99 }
Note: Starting with Build 2012.815, for Game Center compatibility, 'category' may be used instead of 'leaderboardID' and 'value' may be used instead of 'score'.
unlockAchievement: "achievementId"

Game Center (iOS)

Strings supported by the Game Center provider:

  • setHighScore
  • loadScores
  • loadLocalPlayer
  • loadPlayers
  • loadFriends
  • loadAchievements
  • unlockAchievement
  • resetAchievements
  • loadAchievementDescriptions
  • loadFriendRequestMaxNumberOfRecipients
  • loadLeaderboardCategories
  • loadPlayerPhoto
  • loadAchievementImage
  • loadPlaceholderCompletedAchievementImage
  • loadIncompleteAchievementImage

parms

Parmeters used in the above Game Center commands:

setHighScore:

Sets a high score for the currently logged in user for the specified leaderboard (category). If the high score is not higher than the one currently on the server, the server will keep the highest value.

This function corresponds to Apple's reportScoreWithCompletionHandler. The nomenclature deviates in this case to provide consistency with our existing gameNetwork APIs.

Example "setHighScore" request:

gameNetwork.request( "setHighScore",
{
        localPlayerScore = { category="com.appledts.EasyTapList", value=25 },
        listener=requestCallback
})

'localPlayerScore' is a required table that corresponds to Apple's GKScore class.

In the localPlayerScore table:

'category' must be a string that matches the name of the board you want to register the score with as entered on iTunes Connect. (The name you pick need not follow the fully qualified reverse domain style shown here.) '

'value' must be a number representing your score. Note that Apple allows for 64-bit integers, but all numbers in Lua are of type double. This means your max and min values are restricted to the range of double which is about 2^51 instead of 2^64.

loadScores:

event.data in callback listener is an array of items (tables) that have
the following properties:

  • playerID (string)
  • category (string)
  • value (number)
  • context (number, iOS 5+ only)
  • date (string)
  • formattedValue (string)
  • rank (integer)
  • shouldSetDefaultLeaderboard (boolean, iOS 5+ only)

Each item (table) in the array corresponds to Apple's GKScore class.

example:
event.data[5].formattedValue -- #event.data == 2nd value specified in range table

event.localPlayerScore also has all of the above properties (not in an array). This table also corresponds to Apple's GKScore class.

example:
event.localPlayerScore.rank

Warning: iOS 4 has a bug where event.localPlayerScore.category returns nil. This is fixed in iOS 5.

Example "loadScores" request:

gameNetwork.request( "loadScores",
{
        leaderboard =
        {
                category="com.appledts.EasyTapList",
                playerScope="Global",   -- Global, FriendsOnly
                timeScope="AllTime",    -- AllTime, Week, Today
                range={1,5}
        },
        listener=requestCallback
})

'leaderboard' is a required table that corresponds to Apple's GKLeaderboard class.

In the leaderboard table:

'category' (required) must be a string that matches the name of the board you want to fetch the scores with as entered on iTunes Connect. (The name you pick need not follow the fully qualified reverse domain style shown here.) '

'playerScope' (optional) is a string of either "Global" or "FriendsOnly". The latter setting will restrict the fetched scores to only friends.

'timeScope' (optional) is a string of either "AllTime", "Week", "Today" which limits the fetched scores to the specified time range.

'range' (optional) is an array of two values. The first value is that start index. The second value is the number of players to retrieve. Apple says this number must be less than 100. Apple's default range is {1,25}.

loadLocalPlayer
Requests the GKPlayer object for the currently logged-in user.

event.data in callback listener includes the following properties:

  • playerID (string)
  • alias (string)
  • isFriend (boolean)
  • isAuthenticated (boolean)
  • isUnderage (boolean)
  • friends (array)

This table corresponds to Apple's GKLocalPlayer class. Each element in the friends array is a string representing a playerID.

example:
event.data.playerID

Example "loadLocalPlayer" request:

gameNetwork.request( "loadLocalPlayer", { listener=requestCallback } )

Note: To guarantee the friends array is populated, Apple says you must call loadFriends before this. We have found that this necessary on iOS 4, but on iOS 5, we get the friends array regardless.

loadPlayers

Requests a list of players with the specified player IDs, and returns an array of items (tables) for each requested player in the callback listener.

event.data in callback listener is an array of items that
have the following properties:

  • playerID (string)
  • alias (string)
  • isFriend (boolean)

Each item (table) in the array corresponds to Apple's GKPlayer class

example:
event.data[3].isFriend

Example "loadPlayers" request:

gameNetwork.request( "loadPlayers",
{
        playerIDs =
        {
                "G:123456789",
                "G:1234567890",
                "G:0123456789"
        },
        listener=requestCallback
})

loadFriends

Requests the friends of the currently logged in user, and returns and array of tables for all friends in the callback listener.

event.data in callback listener is an array of strings representing playerIDs.

example:
event.data[2].playerID

Example "loadFriends" request:

gameNetwork.request( "loadFriends", { listener=requestCallback } )

loadAchievements

Loads a list of the user's completed achievements for the app and returns an array of items (tables) representing each achievement in the callback listener.

event.data in callback listener is an array of items that have the
following properties (each representing an achievement):

  • identifier (string)
  • percentComplete (number)
  • isCompleted (boolean)
  • isHidden (boolean)
  • lastReportedDate (string)
  • showsCompletionBanner (boolean, iOS 5+ only, will be nil otherwise)

Each item (table) in the array corresponds to Apple's GKAchievement class.

example:
event.data[4].identifier

Example "loadAchievements" request:

gameNetwork.request( "loadAchievements", { listener=requestCallback } )

unlockAchievement

Unlocks the specified achievement (identifier) at the specified percentage. The showsCompletionBanner only takes affect if the achievement is 100% complete, and if the device is running iOS5 or higher.

This function corresponds to Apple's reportAchievementWithCompletionHandler. The nomenclature deviates in this case to provide consistency with our existing gameNetwork APIs.

Example "unlockAchievement" request.

gameNetwork.request( "unlockAchievement",
{
        achievement =
        {
                identifier="com.appletest.one_tap",
                percentComplete=100,
                showsCompletionBanner=true,
        },
        listener=requestCallback
})

'achievement' is a required table that corresponds to Apple's GKAchievement class.

In the "achievement" table:

'identifier' (required) must be a string that matches the name of the achievement you want to unlock/report as entered on iTunes Connect. (The name you pick need not follow the fully qualified reverse domain style shown here.) '

'percentComplete' (optional) must be a number representing the completion percentage of the achievement. 100 will fully unlock the achievement. If this field is omitted, it is assumed this value is 100.

'showsCompletionBanner' (optional, iOS 5+ only) is a boolean which if set to true, will cause Apple to automatically show a completion banner for you in your app when the percentComplete reaches 100. This field is ignored on pre-iOS 5 OS's.

The listener callback will fill event.data with a table that corresponds to the Apple GKAchievement class that you just unlocked. You may use this information to help identify which/any achievements that were successfully reported to the Game Center servers and which ones might have failed due to network timeouts.

resetAchievements

Resets all achievements for the currently logged-in user. Be careful, as there is no undoing this request. Once called, the user will have all achievements for this app reset to 0%.

Example "resetAchievements" request:

gameNetwork.request( "resetAchievements", { listener=requestCallback } )

loadAchievementDescriptions

Requests a list of all descriptions associated with the achievements for the app and returns an array of items (tables) representing each achievement description object in the callback listener.

Each item (table) in the array corresponds to Apple's GKAchievementDescription class.

event.data in callback listener is an array of items which are the
descriptions of your achievements.

  • identifier (string)
  • title (string)
  • achievedDescription (string)
  • unachievedDescription (string)
  • maximumPoints (integer)
  • isHidden (boolean)

Example "loadAchievementDescriptions" request:

gameNetwork.request( "loadAchievementDescriptions", { listener=requestCallback } )

loadFriendRequestMaxNumberOfRecipients

Apple imposes a maximum number of people you may invite in a single friendRequest. This function will allow you to retrieve that number so you may dynamically adapt your code to accommodate this value if it changes. As of this writing, this number is 3. The value will be returned through the callback listener (via event.data).

Example "loadFriendRequestMaxNumberOfRecipients" request:

gameNetwork.request( "loadFriendRequestMaxNumberOfRecipients", { listener=requestCallback } )

loadLeaderboardCategories

Requests a list of leaderboard categories for the app and returns an array of tables with each table containing description information of a leaderboard in the callback listener.

event.data in callback listener is an array of items (tables) where each table contains the keys 'category' and 'title', both of which are strings.

Example "loadLeaderboardCategories" request:

gameNetwork.request( "loadLeaderboardCategories", { listener=requestCallback } )
 
-- example of what an event.data table returned via callback listener looks like
event.data =
{
        [1] = {
                category = "com.appledts.EasyTapList",
                title = "Easy"
        },
        [2] = {
                category = "com.appledts.HardTapList",
                title = "Hard"
        },
        [3] = {
                category = "com.appledts.AwesomeTapList",
                title = "Awesome"
        },
}

loadPlayerPhoto (available starting with Build 2012.730, iOS5+ only)

Retrieves the image of the requested player and creates a display object for it.

Example "loadPlayerPhoto" request.

gameNetwork.request( "loadPlayerPhoto",
{
        playerID = "G:0123456789",
        size="Small", -- "Small" or "Normal"
        listener=requestCallback
})

'playerID' (required) is the Game Center player ID (string) of the player you want to fetch the image for.

'size' (optional) represents the size of the image you want to get back. Supported values are "Small" and "Normal". "Small" is the default.

The listener callback will fill event.data with a table that corresponds to the Apple GKPlayer class as you've seen with other APIs documented above. But unlike the other APIs one additional property is added, 'photo', which is the display object of the retrieved image.

event.data in callback listener includes the following properties:

  • playerID (string)
  • alias (string)
  • isFriend (boolean)
  • isAuthenticated (boolean)
  • isUnderage (boolean)
  • friends (array)
  • photo (display object)

If called on pre-iOS5, the callback will be invoked and return errorCode=1 and errorMessage="This API is not available on this version of iOS."

loadAchievementImage (available starting with Build 2012.730)

Retrieves the image of the requested achievement and creates a display object for it.

Example "loadAchievementImage" request.

gameNetwork.request( "loadAchievementImage",
{
        achievementDescription=
        {
                identifier="com.appledts.twenty_taps"
        },
        listener=requestCallback
})

'achievementDescription' is a required table that corresponds to Apple's GKAchievementDescription class.

In the "achievementDescription" table:

'identifier' (required) must be a string that matches the name of the achievement you want to retrieve the image for. (The name you pick need not follow the fully qualified reverse domain style shown here.) '

The listener callback will fill event.data with a table that corresponds to the Apple GKAchievementDescription class as you've seen with other APIs documented above. But unlike the other APIs one additional property is added, 'image', which is the display object of the retrieved image.

event.data in callback listener includes the following properties:

  • identifier (string)
  • title (string)
  • achievedDescription (string)
  • unachievedDescription (string)
  • maximumPoints (integer)
  • isHidden (boolean)
  • image (display object)

Remember to upload images to iTunes Connect that are compatible with Corona (e.g. don't used indexed color pngs, etc.)

loadPlaceholderCompletedAchievementImage (available starting with Build 2012.730)

Retrieves the Apple placeholder image of a completed achievement and creates a display object for it.

Example "loadPlaceholderCompletedAchievementImage" request.

gameNetwork.request( "loadPlaceholderCompletedAchievementImage",
{
        listener=requestCallback
})

The listener callback will fill event.data with the display object of the image.

loadIncompleteAchievementImage (available starting with Build 2012.730)

Retrieves the Apple placeholder image of an incomplete achievement and creates a display object for it.

Example "loadIncompleteAchievementImage" request.

gameNetwork.request( "loadIncompleteAchievementImage",
{
        listener=requestCallback
})

The listener callback will fill event.data with the display object of the image.

For further property reference for the different objects (GKLeaderboard, GKAchievement, GKAchievementDescription, GKScore, GKPlayer, and GKLocalPlayer), please see the Official Game Kit Framework Reference.

Returns: 

Nothing.
(See listener callback descriptions for data returned through callbacks.)

Supported on:
Mac OS X: 
--
Windows: 
--
iOS: 
Build 2011.556, Game Center: Build 2012.725
Android: 
Build 2011.557, Papaya: Build 2011.591
Remarks: 

Note: This API replaces these deprecated OpenFeint APIs:
openfeint.setHighScore, openfeint.unlockAchievement, openfeint.uploadBlob, openfeint.downloadBlob

Papaya available starting with build 2011.591. (Android only)
Papaya support removed as of build 2012.819. (Android only)
Game Center available starting with build 2012.725 (iOS only)

The following Game Center APIs are available starting with build 2012.730:
loadPlayerPhoto
loadAchievementImage
loadPlaceholderCompletedAchievementImage
loadIncompleteAchievementImage

gameNetwork.show()

Shows (displays) information from game network provider on the screen.

For OpenFeint provider, launches the OpenFeint dashboard in one of the following configurations: leaderboards, challenges, achievements, friends, playing or high score.

For Papaya provider, launches the Papaya dashboard in one of the following configurations: leaderboards, challenges, achievements, friends, avatar, chat, circles, or invites.

Syntax: 

gameNetwork.show( name [, data]  )

Example: 

local gameNetwork = require "gameNetwork"
 
--For OpenFeint:
gameNetwork.init( "openfeint", "product-key", "secret", "display name", "appId" )
gameNetwork.show( "leaderboards" )
gameNetwork.show( "highscore", "abc123" )

local gameNetwork = require "gameNetwork"
 
--For Papaya (Android-only):
gameNetwork.init( "papaya", "papayaSocialKey" )
 
gameNetwork.show( "leaderboards", " Level1" ) 
gameNetwork.show( "leaderboards" )      -- Displays default leaderboard
gameNetwork.show( "achievements" )
gameNetwork.show( "avatar" )
gameNetwork.show( "challenges" )
gameNetwork.show( "chat" )
gameNetwork.show( "circles" )
gameNetwork.show( "friends" )
gameNetwork.show( "invites" )

local gameNetwork = require "gameNetwork"
 
--For GameCenter (iOS-only):
gameNetwork.init( "gamecenter", {listener=initCallback} )
 
gameNetwork.show( "leaderboards", { leaderboard = {timeScope="Week"}, listener=dismissCallback } )
 
gameNetwork.show( "achievements", { listener=dismissCallback } )
 
gameNetwork.show( "friendRequest", { message="By my friend please", playerIDs={ "G:194669300", "G:1435127232" }, emailAddresses={ "me@me.com" },  listener=dismissCallback} )

Parameters: 

name
Strings supported by the OpenFeint provider:

  • "leaderboards"
  • "challenges" (Not supported in Android).
  • "achievements"
  • "friends" (Not supported in Android).
  • "playing" (Not supported in Android).
  • "highscore" NOTE: in this case an additional data string is required (see below). (Not supported in Android).

For OpenFeint, calling gameNetwork.show without this parameter displays the OpenFeint Dashboard.

Note: The items listed above that are not available on Android can still be viewed by going to the OpenFeint Dashboard.

data
String (if Game Center: table): When the OpenFeint dashboard view is "highscore", the string should contain the "leaderboardID" property whose value is the corresponding OpenFeint leaderboard id. Please see example above for data table format for Game Center network.

Strings supported by the Papaya provider:

  • "leaderboards"
  • "leaderboards", "level"
  • "challenges"
  • "achievements"
  • "friends"
  • "avatar"
  • "chat"
  • "circles"
  • "invites"

Strings supported by the Game Center provider:

  • "leaderboards"
  • "achievements"
  • "friendRequest"

All APIs for Game Center support a table as an optional second parameter.
"listener" is an optional key for all the APIs which you may assign a callback function.

For "leaderboards", "leaderboard" is an optional key in the table parameter which takes a table. The table has key/value pairs that mimic the GKLeaderboard (and GKLeaderboardViewController) objects. The key "timeScope" may take one of the following strings:
"Today"
"Week"
"AllTime"

For "friendRequest", optional keys in the table parameter are:
"message" which takes a string which allows you to prepopulate the message field with your own custom text.
"playerIDs" takes an array of strings of Game Center playerIDs to players you want to send a friend request to (which can be retrieved from gameNetwork.request() APIs).
"emailAddresses" takes an array of strings which are email addresses of players you want to send friend requests to.
Note: The total number of playerIDs and emailAddresses must not exceed the Game Center maximum limit or the OS will throw an exception. gameNetwork.request("loadFriendRequestMaxNumberOfRecipients" returns this number. As of this writing, the limit is 3.

Returns: 

Nothing.

Supported on:
Mac OS X: 
--
Windows: 
--
iOS: 
Build 2011.556, Game Center: Build 2012.725
Android: 
Build 2011.557, Papaya: Build 2011.591
Remarks: 

Note: This replaces the depreciated openfeint.launchDashboard API.

Do the following to close the OpenFeint Dashboard:
On Android the Menu button shows a "Exit Feint" button that will exit back to the Corona App. You can also use the Back button to exit (this will go through all the navigated OpenFeint screens and finally exit OpenFeint).

On iOS, there is an "x" in the upper right coroner of the OpenFeint screen that closes the Dashboard.

Papaya available starting with build 2011.591.
Papaya support removed as of build 2012.819.

gameNetwork.init()

Initializes an app with the parameters (e.g., product key, secret, display name, etc.) required by the game network provider.

For more information about Papaya visit the Corona Dashboard. (Papaya is only available for Android.)

Note: Adding "require gameNetwork" to your code will enable Corona Launchpad regardless of the setting in config.lua.

Syntax: 

1
2
3
4
5
6
7
-- OpenFeint/Papaya
gameNetwork.init( providerName [, parms ...] )
 
-- GameCenter
gameNetwork.init( providerName [, initCallback] )
      -- or
gameNetwork.init( "gamecenter", [ {listener=initCallback} ] )

Example: 

local gameNetwork = require "gameNetwork"
 
--For OpenFeint:
gameNetwork.init( "openfeint", "product-key", "secret", "display name", "appId" )
gameNetwork.show( "leaderboards" )
 
--For Papaya:
gameNetwork.init( "papaya", "papayaSocialKey" )
gameNetwork.show( "leaderboards" )
 
-- For GameCenter:
-- It's recommended you call gameNetwork.init() on every
-- "applicationStart" system event.
 
local function initCallback( event )
    if event.data then
        native.showAlert( "Success!", "", { "OK" } )
    end
end
 
local function onSystemEvent( event ) 
    if event.type == "applicationStart" then
        gameNetwork.init( "gamecenter", {listener=initCallback} )
        return true
    end
end
Runtime:addEventListener( "system", onSystemEvent )

Parameters: 

providerName
String of the game network provider. ("openfeint", "papaya", or "gamecenter")

parms
Additional parameters required by the "openfeint" provider.

  • product-key: String of your application's OpenFeint product key (provided by OpenFeint).
  • secret: String of your application's product secret (provided by OpenFeint).
  • display name: String of the name to display in OpenFeint leaderboards and other views.
  • appId: String of the spplication id (provided by OpenFeint).

Additional parameter required by the "papaya" provider

  • papayaSocialKey: String of your application's Papaya Social SDK Key (provided by Papaya).

If using GameCenter, the second argument allows you to specify a callback function. (Instead of secret keys, your bundle identifier is used automatically to identify your app.) On successful login, event.data will be 'true'. On unsuccessful init, event.data will be false. When problems such as network errors occur, event.errorCode (integer) and event.errorMessage (string) will be defined.

Also be aware that iOS backgrounding will cause your app to automatically log out your user from Game Center. When the app is resumed, Game Center will automatically try to re-login your user. The callback function you specified here will be invoked again telling you the result of that re-login attempt. Thus, this callback function exists for the life of your application. With Game Center, it is advisable to avoid calling other Game Center functions when the user is not logged in.

Returns: 

Nothing.

Supported on:
Mac OS X: 
--
Windows: 
--
iOS: 
Build 2011.556
Android: 
Build 2011.557
Remarks: 

Papaya added in build 2011.591. (Android only)
Papaya support removed as of build 2012.819. (Android only)

GameCenter added in build 2012.725 (iOS only).

Note: gameNetwork only supports one provider at a time (you cannot call this API multiple times for different providers).

ads.hide()

Removes the currently shown ad from the screen and prevents new ads from being retrieved until ads.show() has been called again.

For more help on usage, check out our guides for InMobi and inneractive.

Syntax: 

ads.hide()

Example: 

Example for InMobi:

local ads = require "ads"
 
ads.init( "inmobi", "myAppId" )
ads.show( "banner320x48", { x=0, y=100, interval=60, testMode=false } )
 
-- Some time later ...
 
ads.hide()

Example for inneractive:

local ads = require "ads"
 
ads.init( "inneractive", "myAppId" )
ads.show( "banner", { x=0, y=0, interval=60 } )
 
-- Some time later ...
 
ads.hide()

Parameters: 

None.

Returns: 

Nothing.

Supported on:
Mac OS X: 
--
Windows: 
--
iOS: 
Build 2011.556
Android: 
Build 2011.591

ads.show()

Begin showing the ads at the given screen location and the given refresh period.

For more help on usage, check out our guides for InMobi and inneractive.

Note: The ad dimensions are in "points" and not pixels. This means the display size in pixels will be double on a retina display device (e.g., iPhone4).

Syntax: 

 ads.show( adUnitType [, params] )

Example: 

How to use InMobi ads:

local ads = require "ads"
 
local function adListener( event )
    if event.isError then
        -- Failed to receive an ad.
    end
end
 
ads.init( "inmobi", "myAppId", adListener )
ads.show( "banner320x48", { x=0, y=100, interval=60, testMode=false } )

How to use interactive ads:

local ads = require "ads"
 
local function adListener( event )
    if event.isError then
        -- Failed to receive an ad.
    end
end
 
ads.init( "inneractive", "myAppId", adListener )
ads.show( "banner", { x=0, y=0, interval=60 } )

Parameters: 

adUnitType
String indicating the type of ad to show on screen.
InMobi supports the following ad types on all devices:

  • "banner320x48"
  • "banner300x250"

InMobi supports the following larger ad banners types on iPad only:

  • "banner728x90"
  • "banner468x60"
  • "banner120x600"

inneractive supports the following ad types on all devices:

  • "banner"
  • "text"
  • "fullscreen"

params

Optional parameters (table).

  • x = value -- Top left x position in points, not content coordinates. Defaults to 0.
  • y = value -- Top left y position in points, not content coordinates. Defaults to 0.
  • interval = time -- Ad refresh time (in seconds). Defaults to 10.
  • testMode = true|false -- Set to true for testing account. Defaults to false.
Returns: 

Nothing.

Supported on:
Mac OS X: 
--
Windows: 
--
iOS: 
Build 2011.556
Android: 
Build 2011.591
Remarks: 

Be aware that if you are developing a "universal app" (between iPhone3/4 and iPAD), ADs will not dynamically scale to the iPAD. If your config.lua file defines a 320x480 screen, a "320 x 48" ad will appear proportionally smaller on the iPAD than on the iPhone3/4. It's recommended that you detect the device type and choose the proper ad dimensions.

ads.init()

Initialize the Ads service library by specifying the name of the Ads service provider and the appId.

Currently, inneractive and inMobi are supported. For more information see the Corona Dashboard.

For more help on usage, check out our guides for InMobi and inneractive.

Syntax: 

ads.init( providerName, appId [, listener] )

Example: 

How to use InMobi ads:

local ads = require "ads"
 
local function adListener( event )
    if event.isError then
        -- Failed to receive an ad.
    end
end
 
ads.init( "inmobi", "myAppId", adListener )
ads.show( "banner320x48", { x=0, y=100, interval=60, testMode=false } )

How to use interactive ads:

local ads = require "ads"
 
local function adListener( event )
    if event.isError then
        -- Failed to receive an ad.
    end
end
 
ads.init( "inneractive", "myAppId", adListener )
ads.show( "banner", { x=0, y=0, interval=60 } )

Parameters: 

providerName
String containg the provider's name.

appID
String containing the app ID (from xyz site)

listener
Function that will receive an event indicating if showing an ad succeeded or failed. Will be called for every new ad that is requested according to the interval given to the ads.show() function. Provides a property event.isError which will be set true if the system failed to retrieve an ad which can happen if the ad network is unreachable or is out of inventory/ads, in which case nothing is shown on screen. event.isError will be set true if an ad was successfully retrieved and displayed on screen.

Returns: 

Nothing.

Supported on:
Mac OS X: 
--
Windows: 
--
iOS: 
Build 2011.556
Android: 
Build 2011.591
Remarks: 

Note: Adding "require ads" to your code will enable Corona Launchpad regardless of the setting in config.lua.

network.setStatusListener

Starts monitoring a host for its network reachability status.

The API is designed around the idea that you are monitoring individual hosts and not the hardware directly. Potentially, some hosts might continue to be reachable while others are not due to internet conditions, firewall configurations, authentication rules, and whether you need full DNS routing (e.g. not reachable through Bonjour/Zeroconf).

Syntax: 

network.setStatusListener( hostURL, listener )

Example: 

function MyNetworkReachabilityListener(event)
        print( "address", event.address )
        print( "isReachable", event.isReachable )
        print("isConnectionRequired", event.isConnectionRequired)
        print("isConnectionOnDemand", event.isConnectionOnDemand)
        print("IsInteractionRequired", event.isInteractionRequired)
        print("IsReachableViaCellular", event.isReachableViaCellular)
        print("IsReachableViaWiFi", event.isReachableViaWiFi)   
 
--[[ If you want to remove the listener, call network.setStatusListener("www.apple.com", nil)   
        g_Counter = g_Counter + 1
        if g_Counter > 3 then
                print("removing event listener")
                network.setStatusListener( "www.apple.com", nil)
        end
--]]
 
end
 
if network.canDetectNetworkStatusChanges then
        network.setStatusListener( "www.apple.com", MyNetworkReachabilityListener )
else
        print("network reachability not supported on this platform")
end

Parameters: 

hostURL
string: The host you want to monitor. This may be something like "www.apple.com".

listener
function: The callback function you want invoked when a network status change event happens.

If you pass nil here, it will unregister the listener that is set for the specified host.

Returns: 

Nothing.

Supported on:
Mac OS X: 
Build 2011.496
Windows: 
--
iOS: 
Build 2011.496
Android: 
--
Remarks: 

Currently only named hosts are supported. IP addresses will not work.

This API allows monitoring multiple hostURLs with separate or common event listeners. Call this API for each HostURL to be monitored.

Note: There is currently a bug (in Apple's OS?) that returns a false connection status when you specify a URL address with subfolders (e.g., "wwww.apple/xyz") when on the Cellular network. The URL returns the correct connection status when on Wifi.

Sample Programs Using This API
/Networking/Reachability

network.canDetectNetworkStatusChanges

Returns true if network status APIs are supported on the current platform.

Syntax: 

local result = network.canDetectNetworkStatusChanges

Example: 

if network.canDetectNetworkStatusChanges then
        network.setStatusListener( "www.apple.com", MyNetworkReachabilityListener )
else
        print("network reachability not supported on this platform")
end

Parameters: 

None.

Returns: 

Boolean: True if network status is supported on the current platform. False otherwise.

Supported on:
Mac OS X: 
Build 2011.496
Windows: 
--
iOS: 
Build 2011.496
Android: 
--
Remarks: 

Sample Programs Using This API
/Networking/Reachability