AddressBook plugin crash on iOS 9

Hey guys, this issue has been fixed and will be available within 1~2 hours from the time of this post.

The issue was due to the lack of permissions on iOS.

Due to this, we have added a new option to showPopup that allows you to both request permission to the users contact list, and to check your access to the users permission state.

native.canShowPopup(“addressbook”) has also been updated to only return true if you have access to the users contact list.

Whilst the docs are updating, here is the new option you’ll need to use for both requesting and checking your access to the users contacts list:

Api call: native.showPopup("addressbook", {option = "getPermission"})   Gets the permission state of your access to the users contacts. If a permission request has not been issued before, then a permission popup will be shown to request permission to the users contacts. One of the following strings are returned upon calling this function, describing the contact access permission state.   \* "authorized": User authorized access to their contacts. \* "denied": User denied access to their contacts. \* "restricted": Access to the users contact is restricted due to parental settings. \* "requestPermission": A permission popup is shown to request access to the users contacts. After the function returns, you can call native.showPopup("addressbook", {option = "getPermission"}) to check if the user authorized or denied your request. If a permission request was previously denied, this popup cannot be shown again due to iOS limitations. The only way the user can grant access to your app from this point is to enable your app under Settings \> Privacy \> Contacts \> Select your app.

Note: You have to have permission to the users contact list before any of the address book popups can display (for instance, selecting a contact)

Please reply to this thread if you have any additional questions or issues with what I just posted.

Hi Danny, how do we use the native.showPopup(“addressbook”, {option = “getPermission”})?

Would it be like:

local params = { option = "pickContact", hideDetails = true, listener = onContactsComplete } native.showPopup("addressbook", {option = "getPermission"}); native.showPopup( "addressbook", params );

Thanks in advance.

@Dono,

Here’s how I do it.  I added a function to get the Permission Status and then proceed accrodingly.

[lua]

    local function loadAddressBook()

       local PermissionStatus = native.showPopup(“addressbook”, {option = “getPermission”})

        local function checkAuthorization()
            print(“checkAuthorization is called”)
            
            --alert is displayed if Permission is Denied or Restricted
            local function removePermissionAlert(event)
                if “clicked” == event.action then
                    i = event.index
                    if 1 == i then   

                      --dismiss the alert  
                       – audio.play(EnterButtonSound)
                        
                    elseif 2 == i then     
                    else
                    end
                end
                return true
            end
            
            if PermissionStatus == “authorized” then
                print("*****Contact Book Permission authorized")

                – use your existing params and callback function
                native.showPopup( “addressbook”, pickContactOptions )
                
            elseif PermissionStatus == “denied” then
                native.showAlert(“Authorization Denied!”, “To allow Authorization, Go to Settings > Privacy > Contacts > Select YourAppName”, {“OK”}, removePermissionAlert)
           --do something
                
            elseif PermissionStatus == “requestPermission” then
              --if permission is asked for, call the function again to see the requested result

            checkAuthorization()
                
            elseif PermissionStatus == “restricted” then
                native.showAlert(“Authorization Restricted!”, “Access to the users Contacts is restricted due to parental settings”, {“OK”}, removePermissionAlert)
               – do something since permission restricted
                
            else print(“PermissionStatus ==”, PermissionStatus)
               
            end
        end
        
        print(“Flag1 PermissionStatus ==”,PermissionStatus)
        
        checkAuthorization()
        
    end

[/lua]

Hope this helps.

Nail

@Portal5B Thank you very much.

I am seeing this issue too.

I would very much like to use the addressbook plugin in my app, but as it is now it is useless.

@OCG did you submit the bug report?

It appears this is a permission bug introduced by apple in iOS 9.

https://openradar.appspot.com/23006507

Could coronalabs apply the workaround mentioned here?

https://forums.developer.apple.com/thread/11354

@ojnab, I’ve submitted a bugreport last november. 

@OCG thanks then I don’t need to do it.

I guess there isn’t a lot of people using the addressbook plugin since this is getting no attention at all.

Wish someone at CL would take a look at it. It should be fairly simple to fix. 

I fixed this issue a couple of weeks ago.

I wasn’t aware that this thread existed, so my apologies for not replying.

Great. Thanks Danny.

I just tested the plugin and it is still not working for me.

I tested with the addressbook samplecode built for iOS 9.2 with db 2860.

It crashes every time I pick a contact with a ‘linked contact’

Below is my console output when it crashes.

Apr&nbsp; 7 15:05:46 jacobs-iPhone addressbook[941] \<Error\>: \*\*\* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'A contact and its snapshot should both be non-unified.' \*\*\* First throw call stack: (0x18414ae38 0x1837aff80 0x18414ad80 0x18b4d81e4 0x18b4d7e0c 0x18b514ac0 0x18b4e2224 0x18ca9bd3c 0x18c1cff48 0x18c255204 0x18c2559e0 0x183b954bc 0x183b9547c 0x183b9ab84 0x184100dd8 0x1840fec40 0x184028d10 0x185910088 0x1892fdf70 0x10002f518 0x183bc68b8) Apr&nbsp; 7 15:05:46 jacobs-iPhone SpringBoard[54] \<Warning\>: HW kbd: Failed to set com.apple.MobileAddressBook.ContactsViewService as keyboard focus Apr&nbsp; 7 15:05:46 jacobs-iPhone com.apple.xpc.launchd[1] (UIKitApplication:com.ojnab.addressbook[0x5234][941]) \<Notice\>: Service exited due to signal: Abort trap: 6 Apr&nbsp; 7 15:05:46 jacobs-iPhone ContactsViewService[942] \<Warning\>: host connection \<NSXPCConnection: 0x155d3a7f0\> connection from pid 941 invalidated Apr&nbsp; 7 15:05:46 jacobs-iPhone ContactsViewService[942] \<Warning\>: Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (\<UISearchController: 0x155dc38d0\>) Apr&nbsp; 7 15:05:46 jacobs-iPhone diagnosticd[79] \<Error\>: unable to find offset 0x83bbb98c in shared cache for arch 'arm64' Apr&nbsp; 7 15:05:46 jacobs-iPhone ReportCrash[943] \<Notice\>: platform\_thread\_get\_unique\_id matched 380141 Apr&nbsp; 7 15:05:46 jacobs-iPhone ReportCrash[943] \<Notice\>: Formulating report for corpse[941] addressbook Apr&nbsp; 7 15:05:46 jacobs-iPhone mediaserverd[25] \<Notice\>: '' com.apple.MobileAddressBook.ContactsViewService(pid = 942) setting DiscoveryMode = DiscoveryMode\_None, currentDiscoveryMode = DiscoveryMode\_PresenceScan Apr&nbsp; 7 15:05:46 jacobs-iPhone SpringBoard[54] \<Warning\>: HW kbd: Failed to set (null) as keyboard focus Apr&nbsp; 7 15:05:46 jacobs-iPhone SpringBoard[54] \<Warning\>: Application 'UIKitApplication:com.ojnab.addressbook[0x5234]' crashed. Apr&nbsp; 7 15:05:46 jacobs-iPhone UserEventAgent[23] \<Warning\>: 1118954279444: id=com.ojnab.addressbook pid=941, state=0 Apr&nbsp; 7 15:05:46 jacobs-iPhone ReportCrash[943] \<Warning\>: Saved type '109(109\_addressbook)' report (3 of max 25) at /var/mobile/Library/Logs/CrashReporter/addressbook-2016-04-07-150546.ips

This must be a separate issue than the one I fixed then. My apologies.

I’ll look into this today

Yes I think you are right about that.

I seem to remember seeing another crash report than this one.

Thanks. 

Just to be 100% clear… It crashes when a linked contact is selected, no matter what service the linked contact is tied to correct? (i.e iCloud, Facebook etc)

Thanks

Not sure… the only type of linked contacts I have in my phone is “iPhone”

It crashes when I select that.

If I select a contact with no linked contacts it works as supposed to.

That gives me enough to work off.

I’ll update this thread when i’ve got more info.

Thank you. 

Any progress on fixing the addressbook plugin Danny?

Thanks, Nail

Sorry for the delay, been swamped.

Just started looking into this and can reproduce the crash.

I’ll update when I figure out the cause.

Thanks for your patience

Great news Danny!

I’ve got 3 apps that use the AddressBook plugin that can’t be updated without a fix.

Thanks again,

Nail

Hey guys, this issue has been fixed and will be available within 1~2 hours from the time of this post.

The issue was due to the lack of permissions on iOS.

Due to this, we have added a new option to showPopup that allows you to both request permission to the users contact list, and to check your access to the users permission state.

native.canShowPopup(“addressbook”) has also been updated to only return true if you have access to the users contact list.

Whilst the docs are updating, here is the new option you’ll need to use for both requesting and checking your access to the users contacts list:

Api call:&nbsp;native.showPopup("addressbook", {option = "getPermission"}) &nbsp; Gets the permission state of your access to the users contacts. If a permission request has not been issued before, then a permission popup will be shown to request permission to the users contacts. One of the following strings are returned upon calling this function, describing the contact access permission state. &nbsp; \* "authorized": User authorized access to their contacts. \* "denied": User denied access to their contacts. \* "restricted": Access to the users contact is restricted due to parental settings. \* "requestPermission": A permission popup is shown to request access to the users contacts. After the function returns, you can call native.showPopup("addressbook", {option = "getPermission"}) to check if the user authorized or denied your request. If a permission request was previously denied, this popup cannot be shown again due to iOS limitations. The only way the user can grant access to your app from this point is to enable your app under Settings \> Privacy \> Contacts \> Select your app.

Note: You have to have permission to the users contact list before any of the address book popups can display (for instance, selecting a contact)

Please reply to this thread if you have any additional questions or issues with what I just posted.