Facebook Sample Code Under Corona Build 2189a not working on IOS 7.0.4

Hi,

We are pro users and are having a very bad time with the sample code of Facebook connectivity on IPhone 5C, running IOS 7.0.4. We are using XCode 5.1 and Corona Build 2189a, as suggested on the website, but after the app launches, we only see a black screen. 

This works fine on the Simulator but on the actual device all we end up seeing is a black screen. 

Can somebody shed some light on what could possibly go wrong ??

Sunil

Can you post your log error?

I think you forgot to add facebook plugin in build.settings

plugins =
{
[“facebook”] =
{
publisherId = “com.coronalabs”,
supportedPlatforms = { iphone=true, [“iphone-sim”]=true },
},
},

Best Regards,

Team, SP Technolab

www.sptechnolab.com

 settings =

{

orientation =

{

default = “portrait”,

supported = { “portrait” }

},

android =

{

usesPermissions =

{

“android.permission.INTERNET”,

},

},

plugins =

{

– key is the name passed to Lua’s ‘require()’ This section is only required for builds > 2014.2165

[“facebook”] =

{

– required

publisherId = “com.coronalabs”,

supportedPlatforms = { iphone = true, [“iphone-sim”] = true },

},

},

iphone =

{

plist =

{

CFBundleIconFile = “Icon.png”,

CFBundleIconFiles =

{

                “Icon.png”, 

                “Icon@2x.png”, 

                “Icon-60.png”,

                “Icon-60@2x.png”,

                “Icon-72.png”, 

                “Icon-72@2x.png”,

                “Icon-76.png”,

                “Icon-76@2x.png”, 

                “Icon-Small.png”, 

                “Icon-Small@2x.png”,

                “Icon-Small-40.png”,

                “Icon-Small-40@2x.png”,

                “Icon-Small-50.png”, 

                “Icon-Small-50@2x.png”, 

},

UIApplicationExitsOnSuspend = false, – must be false for single sign-on to work

FacebookAppID = “XXXXXXXXXXXXXXXXX”, – replace XXXXXXXXX with your facebook appId

CFBundleURLTypes =

{

{

CFBundleURLSchemes =

{

“fbXXXXXXXXXXXXXXX”, – replace XXXXXXXXX with your facebook appId

}

}

}

}

}

}

Attached is our build settings. The FB APP ID has been hidden on purpose. 

Can you check and let us know what is causing this

Also on Corona Terminal we are getting dvtFoundationBundle : error on Corona Terminal

Dunno what is that for??

Can you post your device log here ?

Best Regards,

Team, SP Technolab

www.sptechnolab.com

SP Technolab is asking the right question.  Usually “It works on the sim but not the device” is the result of something the sim cant test like case sensitive file names, or in the case of Facebook… well Facebook.  You have to tether your device to your computer and use Xcode to peek at the device’s console log.  If you do not know how to do this, please read this tutorial:

http://coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

It is impossible to help without knowing what’s going on and that log is the best way to find out.

Hi,

Rob and SP you are right in asking for the log, but the device that we use for testing which is tethered is an IOS 6.0 IPad and IOS 7.0.5 IPhone 5C is a remote device where we send builds via TestFlight so getting a console log would be difficult. 

What we have done here is we have attached our Facebook code on Dropbox and shared the link for the same, so you can go through the same. 

In Corona 1262 this code brings facebook prompt for IOS 6 and Android devices but same this stop working for IOS 7

So if has stop working can u pls tell me how can i get facebook token in 1262 build of Corona for IOS7 devices

this is working fine on Android and IOS6 devices also. 

Link for Dropbox code of Facebook, it has an App Id also that we have created on Facebook for testing. 

https://www.dropbox.com/s/tk5y5pfcujuzzev/facebook-api-part-II.zip

That’s the link…let us know if there is anything else that we need to share.

Sunil

Also we have been noticing that using Build 2189a or Build 2189 if we build for XCode Simulator, it does launch the IOS 7.1. SDK Simulator that is part of XCode 5.1 but the app does not get installed… which is when on the Corona Terminal we get the dvtFoundationBundle : error

Sunil

Hi evolvingstudios

Still you forgot to add facebook plugin in build.settings

 

plugins =
{
[“facebook”] =
{
publisherId = “com.coronalabs”,
supportedPlatforms = { iphone=true, [“iphone-sim”]=true },
},
},

 

For getting list of Friends you need to call facebook:showDialog( “friends”, listener )    

 

Best Regards,

Team, SP Technolab

www.sptechnolab.com

I am using Corona build : 2014.2189

Best Regards,

Team, SP Technolab

www.sptechnolab.com

At this point, Facebook has made significant changes to their side of things that I don’t know that you can build an app for them with 1262 any more.

We unfortunately can’t build and test your app.  We don’t have the provisioning profiles that match what you’re using, so it would be impossible for us to build with the correct bundle ID that Facebook needs to match.  I would suggest that you join the Corona BETA testers group on Facebook ( There you can solicit people who have volunteered to help test your apps, get their device ID and add it to your testers, generate a build and hook them up through test flight.  They all are Corona developers so they can get console logs for you.  That way you are building against your ID’s

Rob

Hi,

SP / Rob, have attached our code once again which is working perfectly on IOS 6 and Android devices. 

ui = require(“ui”)

local facebook = require “facebook”

require(“Json”)

local widget = require( “widget” )

local myText

local myText1

local appId = “272502539588566”;

local URL;

local userid;

local scrollViewGlobal = nil

local screenGroupp = display.newGroup()

local friendsGroup = display.newGroup()

function onClick( event )

myText.text = event.phase

if(event.phase == “release”) then

facebook.login( appId, listener, {“publish_stream”} )

end

end

function networkListener( event )

if ( event.isError ) then

myText2.text = “networkListener not called”

else

myText2.text = “networkListener called”

local info = event.response

local response = Json.Decode(event.response)

table.foreach(response,print)

print(#response)

myText.text = response.id

userid = response.id

end

end

function listener( event )

myText.text = event.token

    if ( “session” == event.type ) then

        if ( “login” == event.phase ) then

        myText2.text = event.phase

        myText.text = “Token” …event.token

            

            facebook.request(“me”)  

myButton.isVisible = false

            print(“listeners”)

            

            myText2.text = “listener called”

CorrectScore = 10

_G.CorrectToken = event.token

local URL = "http://tampropack.com/api/createuser.php?token="…_G.CorrectToken…"&score="…CorrectScore 

local requestId = network.request( URL,“POST”, networkListener )

        end

    elseif ( “request” == event.type ) then

        local response = Json.Decode( event.response )

local data = response.data

local function showImage( event )

event.target.alpha = 0

event.target.xScale = 0.25

event.target.yScale = 0.25

            transition.to( event.target, { alpha = 1.0 , xScale = 1, yScale = 1} )

end

for i=1,#data do

display.loadRemoteImage(“http://graph.facebook.com/”… data[i].id …"/picture",

“GET”,

showImage,

“friend”…i…".png", 

system.TemporaryDirectory,

math.random(0,display.contentWidth),

math.random(0,display.contentHeight) )

end

    end

end

myButton = ui.newButton {

        defaultSrc = “fb.png” , defaultX = “300” , defaultY = “50”,

        onEvent = onClick,

        id = “myButton”

}

myButton.x = display.contentWidth / 2

myButton.y = display.contentHeight / 2

myText = display.newText( “Hello World!”, 100, 200, native.systemFont, 16 )

myText2 = display.newText( “Hello World!”, 100, 300, native.systemFont, 16 )

The line where we have  local response = Json.Decode(event.response) in the function networkListener   is returning nil is where we are having issues on IOS7, its working well on IOS 6 and ANdroid devices. 

Hope you are able to replicate the issue with the code and help us find a way out. 

The Corona Build used is 1262.

Sunil

There are multiple things going against you here.

1.  Starting sometime in the mid 2100’s, because Apple started rejecting apps that included the ID for Advertisers (IDFA), we had to move the Facebook API to a plugin.  That way, apps not using facebook would not get rejected by Apple.  Apps using Facebook can click the right series of check boxes and get approved.   To use any of the later builds including 2189a, you must include the necessary code in your build.settings file.   Your build.settings file in your zip file is missing that code.  SP Technolab provided the required code for you to use above twice.  You will simply not work with 2189 or later if you do not do this.  This is for iOS only.  On Android, it’s not a plugin.  See: http://docs.coronalabs.com/api/library/facebook/index.html

2.  Since Corona SDK is now using Facebook as a plugin (and for Android running later builds), we are now using the SDK v2 protocol for Facebook.  1262 is built against the older protocol.  You need to do a 2-step login.  The first time requests basic permissions and sets up your listener.  The second time, you can request enhanced permissions, though it seems that Facebook is now going through some form of approval process for apps that want extended permissions.

3.  If you get a black screen on the device, we need to know what’s in the device’s console log.  I provided a tutorial above that shows you how to get that information.  I don’t see where you provided it.  It will likely point to problems.  You can also put in print statements to see what the network listener is returning and maybe get some clues there.  But it starts with reading that console log.

So if you want to use a more modern build (which you very likely will have to do to pass both Apple and Facebook requirements) you have to include the plugin code and abide by the latest Facebook way of doing things.

Rob

Hi !

i’m getting this error with my app 
Runtime error?:0: attempt to call field ‘login’ (a nil value)stack traceback:

and I try the file from the Link for Dropbox code of Facebook and the same… Any Help!! 

That sounds like you are not including the required plugin code in your build.settings or there is an error in your build.settings.   There are probably more messages in your device’s console log that could pin point this. 

If you don’t know how to read your console log, consult this post:   http://coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

Please post the relevant part of your console log here, along with your build.settings, your code you are using to initialize and login to facebook as well.

Also what version of Corona SDK are you using?

What platform are you trying to build for and build on?

Hi Rob

Corona Version 2189

IOS app

 

Using additional build settings from: /Users/plmarcot/Library/Application Support/Outlaw/Sandbox/96/build.settings

 

mv: rename /Users/plmarcot/Desktop/BuildCorona/facebook.app/icon.png to /Users/plmarcot/Desktop/BuildCorona/facebook.app/Icon.png: No such file or directory

 

App Spec: <DTiPhoneSimulatorApplicationSpecifier 0x7f8710d369b0> specified by path /Users/plmarcot/Desktop/BuildCorona/facebook.app

SDK Root: <DTiPhoneSimulatorSystemRoot 0x7f8710d33260> path=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk version=7.1 name=Simulator - iOS 7.1

Creating named pipe at `/var/folders/qv/r1rb5mms5b58jy8bbz5sjg5m0000gn/T//ios-sim-stderr-pipe-1401655179’

Creating named pipe at `/var/folders/qv/r1rb5mms5b58jy8bbz5sjg5m0000gn/T//ios-sim-stdout-pipe-1401655179’

using device family iphone

using retina

SimulateDevice: iPhone Retina (4-inch)

Calling: setSimulatedDeviceInfoName: iPhone Retina (4-inch) (iPhone Retina (4-inch 64-bit))

 

Session started

 

2014-06-01 16:40:09.037 facebook[9160:70b] Platform: iPhone Simulator / x86_64 / 7.1 / Apple Software Renderer / OpenGL ES 2.0 APPLE-9.4.3

2014-06-01 16:40:09.082 facebook[9160:70b] fb1389327051306781

2014-06-01 16:40:09.083 facebook[9160:70b] Runtime error

/Users/plmarcot/Library/Application Support/Outlaw/Sandbox/96/main.lua:19: attempt to call field ‘login’ (a nil value)

stack traceback:

/Users/plmarcot/Library/Application Support/Outlaw/Sandbox/96/main.lua:19: in main chunk

 

2014-06-01 16:40:09.372 facebook[9160:70b] AppDelegate.mm: didFailToRegisterForRemoteNotificationsWithError: remote notifications are not supported in the simulator

What is line 19 of your main.lua?

Are you doing a:   local facebook = require(“facebook”)? 

What does your build.settings look like?

settings = { orientation = { default = "landscapeRight", supported = { "landscapeLeft", "landscapeRight" }, }, plugins = { -- key is the name passed to Lua's 'require()' ["CoronaProvider.ads.iads"] = { -- required publisherId = "com.coronalabs", ["facebook"] = { publisherId = "com.coronalabs", supportedPlatforms = { iphone=true, ["iphone-sim"]=true }, }, iphone = { plist= { UIApplicationExitsOnSuspend = false, FacebookAppID = "1510121132542868", CFBundleURLTypes = { { CFBundleURLSchemes = { "fb1510121132542868", CFBundleIconFiles = { "Icon.png", "Icon@2x.png", "Icon-Small-40.png", "Icon-Small-40@2x.png", "Icon-60.png", "Icon-60@2x.png", "Icon-72.png", "Icon-72@2x.png", "Icon-76.png", "Icon-76@2x.png", "Icon-Small-50.png", "Icon-Small-50@2x.png", "Icon-Small.png", "Icon-Small@2x.png" } } } } }, }, }, }, }

19- facebook.login( FBAppID, listener, { “publish_actions” } )

It looks to me like you have an error in your build.settings file. 

&nbsp;&nbsp;&nbsp;&nbsp; plugins = &nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- key is the name passed to Lua's 'require()' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ["CoronaProvider.ads.iads"] = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- required &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; publisherId = "com.coronalabs", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ["facebook"] = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; publisherId = "com.coronalabs", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; supportedPlatforms = { iphone=true, ["iphone-sim"]=true }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }, &nbsp;&nbsp;&nbsp; },

You’re braces are not ending correctly.  It really helps to indent your code for each level so you can quickly line up the braces and spot errors.  I had to close two sets of braces to balance things out.  A quick look above makes me thing you have too many braces at the bottom.  Spend some time getting your indents correct and make sure everything is at the right level.  The plugin block is a peer to iphone, orientation, etc.

Thanks Rob!! The problem was the braces.