0
votes

I am running Xcode 4.2 with an imported IOS 6 SDK (older Mac incapable of running XCode 4.5). My app is configured with an iOS Deployment Target of 4.3, a Base SDK of 6.0, and Architectures of armv7 only.

I am trying to update my previously working app to request permission to access a user's address book, which is now a requirement for iOS 6 (using the new iOS 6 functions). Unfortunately, I am receiving the following Apple Mach-O Linker Error:

Ld /Users/Blake/Library/Developer/Xcode/DerivedData/MyApp-ercibgqhpidlmwflixmwbvruyctz/Build/Products/Debug-iphoneos/MyApp.app/MyApp normal armv7 cd /Users/Blake/Desktop/MyApp/MyApp setenv IPHONEOS_DEPLOYMENT_TARGET 4.3 setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang -arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -L/Users/Blake/Library/Developer/Xcode/DerivedData/MyApp-ercibgqhpidlmwflixmwbvruyctz/Build/Products/Debug-iphoneos -L/Users/Blake/Desktop/MyApp/MyApp/../../../Downloads/ScannerKit-Latest/Demo/Libraries/ScannerKit -F/Users/Blake/Library/Developer/Xcode/DerivedData/MyApp-ercibgqhpidlmwflixmwbvruyctz/Build/Products/Debug-iphoneos -filelist /Users/Blake/Library/Developer/Xcode/DerivedData/MyApp-ercibgqhpidlmwflixmwbvruyctz/Build/Intermediates/MyApp.build/Debug-iphoneos/MyApp.build/Objects-normal/armv7/MyApp.LinkFileList -dead_strip -all_load -lstdc++ -fobjc-arc -miphoneos-version-min=4.3 -framework AddressBook -framework AddressBookUI -framework UIKit -framework Foundation -framework CoreGraphics -lScannerKit -framework AVFoundation -framework CoreMedia -framework SystemConfiguration -framework CoreVideo -liconv -framework AudioToolbox -framework QuartzCore -o /Users/Blake/Library/Developer/Xcode/DerivedData/MyApp-ercibgqhpidlmwflixmwbvruyctz/Build/Products/Debug-iphoneos/MyApp.app/MyApp

Undefined symbols for architecture armv7:
"_ABAddressBookRequestAccessWithCompletion", referenced from: -[ServerConnect parserDidEndDocument:] in ServerConnect.o "_ABAddressBookGetAuthorizationStatus", referenced from: -[ServerConnect parserDidEndDocument:] in ServerConnect.o "_ABAddressBookCreateWithOptions", referenced from: -[ServerConnect parserDidEndDocument:] in ServerConnect.o ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

My best guess is that XCode 4.2 is looking in the iPhoneOS5.0.sdk instead of my iPhoneOS6.0.sdk for architecture armv7. However, I am unable to see where I can fix this problem. Has anyone else encountered this problem before? Thanks for any help in advance!

My Code (for Reference):

// Fetch the address book 
//Check if we are using iOS6
if ([self isABAddressBookCreateWithOptionsAvailable]) {
        ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);

        if (ABAddressBookGetAuthorizationStatus() == 0) {
            ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
                // First time access has been granted
                [self searchForPersonInAddressBook:addressBook withName:fullName];
            });
        }
        else if (ABAddressBookGetAuthorizationStatus() == 3) {
            // The user has previously given access
            [self searchForPersonInAddressBook:addressBook withName:fullName];
        }
        else {
            // The user has previously denied access
            UIAlertView *deniedAccess=[[UIAlertView alloc] initWithTitle:@"Unable to Access Address Book" message:@"Change App Privacy Settings" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [deniedAccess show];
        }
    }
    //If using iOS 4/5
    else {
        ABAddressBookRef addressBook = ABAddressBookCreate();
        [self searchForPersonInAddressBook:addressBook withName:fullName];
    }
}

- (void)searchForPersonInAddressBook:(ABAddressBookRef )ab
                withName:(NSString *)fn
{
// Search for the person in the address book
CFArrayRef person = ABAddressBookCopyPeopleWithName(ab, (__bridge CFStringRef)fn);
// Display message if person not found in the address book 
if ((person != nil) && (CFArrayGetCount(person) == 0)) {
    // Show an alert if name is not in Contacts
    UIAlertView *saveContact=[[UIAlertView alloc] initWithTitle:@"Save New Contact to iPhone?" message:fn delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Save!", nil];
    saveContact.tag = 2;
    [saveContact show];
}
}

- (BOOL)isABAddressBookCreateWithOptionsAvailable
{
     return &ABAddressBookCreateWithOptions != NULL;
}
2

2 Answers

1
votes

That's the type of error you usually get if you don't link the framework to your project. So you probably imported your headers (thus no compile time error) however, you didn't add AddressBook.framework from TargetName->Build Phases->Link Binary With Libraries

0
votes

I solved my problem through weak linking the AddressBook Frameworks in the "Link Binary with Libraries" Section of my Target's Build Phases Settings ("Optional" instead of "Required").

Also, I believe there is an XCode4.2 bug in which it duplicates the device destination. For some reason, after choosing the duplicate, my app was able to compile (See the following link: How to access weak linked framework in iOS?).