Apple Sign-In Plugin

My latest app update was rejected due to a lack of Apple Sign-In (institutional policy was to require LinkedIn login exclusively). I’m trying to incorporate Scott’s Apple Sign-In plugin with no success.

Using it as the documentation suggests, I get this error on app startup in Xcode simulator:

Runtime error: module 'plugin.appleSignIn' not found:resource (plugin.appleSignIn.lu) does not exist in archive no field package.preload['plugin.appleSignIn'] no file '/Users/joseph/Library/Developer/CoreSimulator/Devices/2B352632-10DA-43DF-8C20-7306E42791B1/data/Containers/Bundle/Application/8E148A70-7728-4E27-B582-7BC11F66FBE5/Propass.app/corona-plugins/plugin/appleSignIn.lua'

In the Solar2D simulator, the app loads fine but when I click the Sign-In button I get “WARNING: The ‘plugin.appleSignIn’ library is not available on this platform.” and nothing happens (not unexpected).

If I run the example app Scott loaded to GitHub, I get the same warning response in the Solar2D simulator. It doesn’t error out in Xcode but the button effectively does nothing. I’m never prompted to sign-in, and nothing ever hits the system log. His build.settings in the example app does not match his documentation setting since it lacks the marketplace ID argument. If I drop the marketplace ID argument before building for the xCode, I stop getting the error but my button does nothing.

I know next to nothing about plugins, but looking at the tar files in my Solar2D plugins folder, it appears the extent of the code there is simply to print that warning message and nothing else.

I have activated the plugin through my account at Solar2Dmarketplace.com and the profile I’m using to build has the Apple Sign In entitlement.

Here is my build.settings (marketplaceID intentionally removed):

settings = {
	orientation = {
		default = "portrait",
		supported = {"portrait", "portraitUpsideDown"},
	},
  iphone =
    {
        xcassets = "Images.xcassets",
        plist =
        {
            CFBundleIconFiles = {},  
            UILaunchStoryboardName = "LaunchScreen",  
            CoronaWindowMovesWhenKeyboardAppears = true
        },
        entitlements = {
            ["com.apple.developer.applesignin"] = {"Default"},
        }
    },
  
  plugins = {
		["plugin.appleSignIn"] =
          {			
              publisherId = "tech.scotth",
              marketplaceId = "******",
          },
    },
}

And the relevant part of my sign-in page:

local composer = require( "composer" )
local widget = require "widget"
local appleSignIn = require "plugin.appleSignIn"
local json = require "json"
local centerX = display.contentCenterX
local centerY = display.contentCenterY
local screenTop = display.screenOriginY
local screenLeft = display.screenOriginX
local bottomMarg = display.contentHeight - display.screenOriginY
local rightMarg = display.contentWidth - display.screenOriginX

function AppleSignInButtonOnPressHandler( event )

  print("You pressed the button AppleSignInButton")
  LISigninButton.alpha = 0
  AppleSignInButton.alpha = 0
  
  
		appleSignIn.show("name", function (e)
		    print(json.encode(e))
		 end    )
  
end

AppleSignInButton = widget.newButton({
  x = centerX,
  y = centerY-100,
  width = 500,
  height = 100,
  id = "AppleSignInButton",
  label = "",
  labelAlign = "center",
  font = "Helvetica Neue",
  fontSize = 22,
  labelColor = { default = {0.25, 0.54, 0.87, 1.0}, over = {0.17, 0.37, 0.61, 1.0} },
  defaultFile = "appleSignIn.png",
  overFile = "appleSignIn.png",
  onPress = AppleSignInButtonOnPressHandler,
})

If anyone has gotten this plugin working and can give me some advice, it would be much appreciated!

Have you tried running on device, I don’t believe my plugins work on simulator yet

Interestingly I hadn’t even gotten to that step since even the most basic version wasn’t running in Xcode. So here’s what I found:

I went ahead and wrote out the rest of the function to fit my app’s needs and sort of crossed my fingers that I got it right since debugging on the device vs the sim would be more of a pain. Sent over to my device and got the same runtime error when I opened the app.

I loaded your demo over to the phone to see if that would work, and sure enough it did.

On a hunch, I edited the marketplaceID argument out of the build.settings for my app, since your demo build.settings doesn’t include that line and it seemed the only real difference in a pretty simple implementation.

Voila, the app opens fine and the entire Apple Sign-In process works great on the device. Still need to do some work idiot-proofing the logic that integrates this into my previous sign-in script, but the plugin definitely does work!

Thanks for your work and the quick response here :smiley:

1 Like

My app has been rejected because it has only Facebook login. Now, I need to add “Sign in with Apple”, but the demo of the plugin crashes on the device all the time without giving any errors. Any ideas about the cause?

Edit: I solved it. I was using iOS 12.4.8. I noticed plugin works with 13.0+.

1 Like

I use the plugin like this :

local g_appleSignIn
if sg_appPreferences.osPlatform == OS_PLATFORMS.IOS then
	g_appleSignIn = require "plugin.appleSignIn"
end

if g_appleSignIn ~= nil then
	g_appleSignIn.show("nameAndEmail", function ( event )

		if event.isError == true then

		else
			-- Has :
			-- 1) event.user
			-- 2) event.email
			-- if event.fullName ~= nil and event.fullName.givenName ~= nil then 
				-- 3) event.fullName.givenName 
			-- end
			
	end
end

If you put brackets around “widget” & “json”, it works exactly the same as without them… but as for appleSignIn, there MUST BE NO brackets!

Why is that?

You can omit brackets if you want in Lua functions where you have only a single argument and said argument is a string, i.e. there’s no difference if you require modules/plugins with or without brackets.

-- These are the same:
local appleSignIn = require( "plugin.appleSignIn" )
local appleSignIn = require "plugin.appleSignIn"
-- And these two are the same:
print( "hello" )
print "hello"

Because SignIn plugin will not be loaded if brackets are used. Check yourself.

In my case for some reason if I put brackets the plugin is not loaded… I can give you screenshots.

I’ve configured my two oldest apps to use appleSignIn. I’ve updated my provisioning profiles and implemented the code that is working in my latest app. But for some reason, I’m getting this message (event) from the appleSignIn plugin:

{“isError”:true,“error”:“The operation couldn’t be completed. (com.apple.AuthenticationServices.AuthorizationError error 1000.)”,“name”:“appleSignIn”}

I’m calling it with this: signIn.show(“nameAndEmail”, L_appleSignIn)

building with the latest Solar2D v2022.3682

Any ideas?

Did you add entitlement in your build.settings and provisioning profile?
https://scotth.tech/plugin-appleSignIn

1 Like

@Scott_Harrison Thank you, that was such an elementary problem. The reason I had forgotten the entitlements is because I mistakenly thought the build.settings details in the main plugin page was all there was. See attached. Might I recommend you add “…and more on Documentations page” underneath the preview area? :slight_smile:

1 Like