0

我正在使用导入的 IOS 6 SDK 运行 Xcode 4.2(旧 Mac 无法运行 XCode 4.5)。我的应用程序配置了 4.3 的 iOS 部署目标、6.0 的基本 SDK 和 armv7 的体系结构。

我正在尝试更新我以前工作的应用程序以请求访问用户地址簿的权限,这现在是 iOS 6 的要求(使用新的 iOS 6 功能)。不幸的是,我收到以下 Apple Mach-O 链接器错误:

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/调试-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应用程序/我的应用程序应用程序/我的应用程序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 -框架 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/MyAppbuild/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 -框架 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/MyApp3 -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/MyApp3 -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

架构 armv7 的未定义符号:
_ABAddressBookRequestAccessWithCompletion ”,引用自:ServerConnect.o 中的-[ServerConnect parserDidEndDocument:]“ _ABAddressBookGetAuthorizationStatus ”,引用自:ServerConnect.o 中的-[ServerConnect parserDidEndDocument:]“ _ABAddressBookCreateWithOptions ”,引用自:-[ServerConnect ServerConnect.o ld 中的 parserDidEndDocument:]:未找到架构 armv7 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)

我最好的猜测是 XCode 4.2 正在寻找 iPhoneOS5.0.sdk 而不是我的 iPhoneOS6.0.sdk 架构 armv7。但是,我看不到在哪里可以解决此问题。以前有没有其他人遇到过这个问题?提前感谢您的帮助!

我的代码(供参考):

// 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;
}
4

2 回答 2

1

如果您没有将框架链接到您的项目,这就是您通常会遇到的错误类型。所以你可能导入了你的头文件(因此没有编译时错误)但是,你没有添加AddressBook.frameworkfromTargetName->Build Phases->Link Binary With Libraries

于 2013-01-13T22:42:45.237 回答
0

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?).

于 2013-01-15T07:46:34.817 回答