Send custom email to selected phone contact iOS 9 problem

Hi, in a previous threat I asked how to send an email to a phone contact the solution they give me it was working on iOS 8.4 but in iOS 9 it crash.

Here is my code

local function inviteContactsEmail( event ) if event.phase=="ended" or event.phase=="cancelled" then local pickContactOptions = { option = "pickContact", hideDetails = true, performDefaultAction = true, filter = { "email" }, listener = function ( event ) local email="" local subject=translations["About1"][myApp.userPreferences.language] local body=myApp.userData.username..translations["InviteToDownload"][myApp.userPreferences.language] if ( event.data ) then for k,v in pairs( event.data ) do if k=="homeEmail" then print( k, ":", v ) email=v end end if email=="" then timer.performWithDelay(2000, function( ) native.showAlert( "Contact", translations["contact\_no\_email"][myApp.userPreferences.language], {"OK"}) end); else timer.performWithDelay(2000, function( ) local options = { to = email, subject =translations["About1"][myApp.userPreferences.language], body=myApp.userData.username..translations["InviteToDownload"][myApp.userPreferences.language], } native.showPopup("mail", options) end); end end end } native.showPopup( "addressbook", pickContactOptions ) end return true end

and this is the device log

Sep 21 09:44:39 KaosiPadAir2 SpringBoard[1114] <Warning>: HW kbd: Failed to set com.apple.MobileAddressBook.ContactsViewService as keyboard focus

Sep 21 09:44:39 KaosiPadAir2 SpringBoard[1114] <Warning>: HW kbd: Failed to set com.apple.MobileAddressBook.ContactsViewService as keyboard focus

Sep 21 09:44:39 KaosiPadAir2 mediaserverd[1085] <Notice>: ‘’ com.islandofthemoon.morbido(pid = 1402) setting DiscoveryMode = DiscoveryMode_None, currentDiscoveryMode = DiscoveryMode_None

Sep 21 09:44:39 KaosiPadAir2 SpringBoard[1114] <Warning>: UNNotificationRegistrarConnectionListener connection invalidated

Sep 21 09:44:39 KaosiPadAir2 mediaserverd[1085] <Notice>: ‘’ (pid = 1402) setting DiscoveryMode = DiscoveryMode_None, currentDiscoveryMode = DiscoveryMode_None

Sep 21 09:44:39 KaosiPadAir2 mediaserverd[1085] <Notice>: ‘’ com.islandofthemoon.morbido(pid = 1402) setting DiscoveryMode = DiscoveryMode_None, currentDiscoveryMode = DiscoveryMode_None

Sep 21 09:44:39 KaosiPadAir2 ContactsViewService[1405] <Warning>: host connection <NSXPCConnection: 0x15fd256a0> connection from pid 1402 invalidated

Sep 21 09:44:39 KaosiPadAir2 com.apple.xpc.launchd[1] (UIKitApplication:com.islandofthemoon.morbido[0xb91d][1402]) <Notice>: Service exited due to signal: Segmentation fault: 11

Sep 21 09:44:39 KaosiPadAir2 mediaserverd[1085] <Notice>: ‘FigPlayer - 1091’ (pid = 1091) setting DiscoveryMode = DiscoveryMode_None, currentDiscoveryMode = DiscoveryMode_None

Sep 21 09:44:39 KaosiPadAir2 SpringBoard[1114] <Warning>: HW kbd: Failed to set (null) as keyboard focus

Sep 21 09:44:39 KaosiPadAir2 SpringBoard[1114] <Warning>: [<_UIKeyboardArbiterHandle: 0x148527570; PID 1207: com.apple.accessibility.AccessibilityUIServer <(null)>; hosting PIDs {(

)}; level 0.000000; active NO [wants NO]; suppression 0>] could not take process assertion

Sep 21 09:44:39 KaosiPadAir2 diagnosticd[1142] <Error>: unable to find offset 0x97440ac4 in shared cache for arch ‘arm64’

Sep 21 09:44:39 KaosiPadAir2 ReportCrash[1407] <Notice>: platform_thread_get_unique_id matched 463020

Sep 21 09:44:39 KaosiPadAir2 ReportCrash[1407] <Notice>: Formulating report for corpse[1402] Esa Maldita App

Sep 21 09:44:39 KaosiPadAir2 mediaserverd[1085] <Notice>: ‘’ (pid = 1405) setting DiscoveryMode = DiscoveryMode_None, currentDiscoveryMode = DiscoveryMode_None

Sep 21 09:44:39 KaosiPadAir2 SpringBoard[1114] <Warning>: HW kbd: Failed to set (null) as keyboard focus

Sep 21 09:44:39 KaosiPadAir2 ReportCrash[1407] <Warning>: saved type ‘109_Esa Maldita App’ report (1 of max 25) as /var/mobile/Library/Logs/CrashReporter/Esa Maldita App_2015-09-21-094439_KaosiPadAir2.ips.beta

Sep 21 09:44:39 KaosiPadAir2 SpringBoard[1114] <Warning>: Application ‘UIKitApplication:com.islandofthemoon.morbido[0xb91d]’ crashed.

Sep 21 09:44:39 KaosiPadAir2 UserEventAgent[1083] <Warning>: 3191392643339: id=com.islandofthemoon.morbido pid=1402, state=0

Sep 21 09:44:39 KaosiPadAir2 duetexpertd[1213] <Warning>: mme: com.islandofthemoon.morbido, 2015-09-21 13:44:39 +0000, 

Sep 21 09:44:39 KaosiPadAir2 SpringBoard[1114] <Warning>: [MPUSystemMediaControls] Updating supported commands for now playing application.

Sep 21 09:44:39 KaosiPadAir2 SpringBoard[1114] <Warning>: [MPUSystemMediaControls] Updating supported commands for now playing application.

Sep 21 09:44:39 KaosiPadAir2 SpringBoard[1114] <Warning>: Unable to get short BSD proc info for 1402: No such process

Sep 21 09:44:39 KaosiPadAir2 SpringBoard[1114] <Warning>: [MPUSystemMediaControls] Updating supported commands for now playing application.

Sep 21 09:44:39 KaosiPadAir2 SpringBoard[1114] <Warning>: [MPUSystemMediaControls] Updating supported commands for now playing application.

Sep 21 09:44:39 KaosiPadAir2 searchd[1206] <Warning>: ====^^^^ DuetExpert missing requested data, people:0 applicationDeepLinks:1 applications:0 requests:18 missingAllDataRequests:0

Sep 21 09:44:50 KaosiPadAir2 OTACrashCopier[1408] <Notice>: (Warn ) <OTACrashCopierController.m __42-[OTACrashCopierController handleRequest:]_block_invoke:527> Creating Power Assertion for 600 secs

Checking the device logs I have found this error 

“contact and its snapshot should both be non-unified.”

This error happened when I click in a contact and crash the app

in the iOS forum I found a solution to this error 

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

it looks like it’s a permission error and the new iOS 9 require permission for address book explicit

Can I get you to file a bug report on this please. A simple example that generates the crash. It will need at a minimum a main.lua, build.settings, config.lua and any assets needed.  Compress up that folder into a .zip file and use the “Report a Bug” link at the top of the page.

Make sure in the text of the bug report to link to this thread as well as the Apple forums links ( When you get the bug report confirmation in email, please post the CaseID # back here.

Thanks

Rob

I am seeing another problem in the debugger. This also blows up in IOSAddressBookNativePopupProvider.mm:

// Loop through the emails for ( int j = 0; j \< ABMultiValueGetCount( emailAddresses ); j ++ ) { NSString \*email = (NSString \*)ABMultiValueCopyValueAtIndex(emailAddresses, j); NSString \*key = (NSString \*)ABMultiValueCopyLabelAtIndex(emailAddresses, j); &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( [key isEqualToString:(NSString\*)kABHomeLabel] ) key = @"homeEmail"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else if ( [key isEqualToString:(NSString\*)kABWorkLabel] ) key = @"workEmail"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // iCloud label is only default on iOS 7+. Doesn't have a constant defined in AddressBook/ABPerson.h &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else if ( [key isEqualToString:@"iCloud"] ) key = @"ICloudEmail"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else if ( [key isEqualToString:(NSString\*)kABOtherLabel] ) key = @"otherEmail"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Append "Email" prefix if using a custom label &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else key = [key stringByAppendingString:@"Email"]; lua\_pushstring( self.luaState, [email UTF8String] ); // Value lua\_setfield( self.luaState, -2, [key UTF8String] ); // Key }

The problem is that, with some non-linked contacts, there is an email address for which “key” is nil. When you look at the contact in the phone, the label says “email” – not “home”, “work”, “other”, etc. But the code returns nil for key, so the else clause doesn’t set key, so key is nil  when lua_setfield() is called, and it blows up.

It’s another bug. I’ve worked around it by setting key to “otherEmail” if it’s nil.

There’s more to this, btw. ABAddressBook and its related classes are deprecated in iOS 9 (sigh), so at some point, the entire plugin will have to be updated.

And it’s def an iOS 9 bug that gabriel is experiencing, and the workaround is to ask the user for access to all contacts, even though that’s not supposed to be required when getting a single contact back from ABPeoplePickerNavigationController.

I’ve worked around the iOS 9 bug by adding this code in showPopup() of IOSAddressBookNativePopupProvider.mm:

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Show the picker &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //result = pickContact( L, appViewController, delegate ); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //iOS 9 bug fix for linked contacts. Lines below replace the line above. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ABAddressBookRef addressBook =&nbsp; ABAddressBookCreateWithOptions(NULL, NULL); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( granted ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pickContact( L, appViewController, delegate ); &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result = 0;

Has anyone filed a bug report on this yet?

I haven’t. It iOS thing is an Apple bug. The one with key=nil is probably a legit plugin bug, but since it didn’t happen until iOS 9 either, I wonder if Apple will make that one go away, too.

Checking the device logs I have found this error 

“contact and its snapshot should both be non-unified.”

This error happened when I click in a contact and crash the app

in the iOS forum I found a solution to this error 

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

it looks like it’s a permission error and the new iOS 9 require permission for address book explicit

Can I get you to file a bug report on this please. A simple example that generates the crash. It will need at a minimum a main.lua, build.settings, config.lua and any assets needed.  Compress up that folder into a .zip file and use the “Report a Bug” link at the top of the page.

Make sure in the text of the bug report to link to this thread as well as the Apple forums links ( When you get the bug report confirmation in email, please post the CaseID # back here.

Thanks

Rob

I am seeing another problem in the debugger. This also blows up in IOSAddressBookNativePopupProvider.mm:

// Loop through the emails for ( int j = 0; j \< ABMultiValueGetCount( emailAddresses ); j ++ ) { NSString \*email = (NSString \*)ABMultiValueCopyValueAtIndex(emailAddresses, j); NSString \*key = (NSString \*)ABMultiValueCopyLabelAtIndex(emailAddresses, j); &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( [key isEqualToString:(NSString\*)kABHomeLabel] ) key = @"homeEmail"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else if ( [key isEqualToString:(NSString\*)kABWorkLabel] ) key = @"workEmail"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // iCloud label is only default on iOS 7+. Doesn't have a constant defined in AddressBook/ABPerson.h &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else if ( [key isEqualToString:@"iCloud"] ) key = @"ICloudEmail"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else if ( [key isEqualToString:(NSString\*)kABOtherLabel] ) key = @"otherEmail"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Append "Email" prefix if using a custom label &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else key = [key stringByAppendingString:@"Email"]; lua\_pushstring( self.luaState, [email UTF8String] ); // Value lua\_setfield( self.luaState, -2, [key UTF8String] ); // Key }

The problem is that, with some non-linked contacts, there is an email address for which “key” is nil. When you look at the contact in the phone, the label says “email” – not “home”, “work”, “other”, etc. But the code returns nil for key, so the else clause doesn’t set key, so key is nil  when lua_setfield() is called, and it blows up.

It’s another bug. I’ve worked around it by setting key to “otherEmail” if it’s nil.

There’s more to this, btw. ABAddressBook and its related classes are deprecated in iOS 9 (sigh), so at some point, the entire plugin will have to be updated.

And it’s def an iOS 9 bug that gabriel is experiencing, and the workaround is to ask the user for access to all contacts, even though that’s not supposed to be required when getting a single contact back from ABPeoplePickerNavigationController.

I’ve worked around the iOS 9 bug by adding this code in showPopup() of IOSAddressBookNativePopupProvider.mm:

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Show the picker &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //result = pickContact( L, appViewController, delegate ); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //iOS 9 bug fix for linked contacts. Lines below replace the line above. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ABAddressBookRef addressBook =&nbsp; ABAddressBookCreateWithOptions(NULL, NULL); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( granted ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pickContact( L, appViewController, delegate ); &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result = 0;

Has anyone filed a bug report on this yet?

I haven’t. It iOS thing is an Apple bug. The one with key=nil is probably a legit plugin bug, but since it didn’t happen until iOS 9 either, I wonder if Apple will make that one go away, too.