XCode:苹果Mach-O链接器错误与新的iOS 6 ABAddressBook函数
我正在运行Xcode 4.2与导入IOS 6 SDK(旧的Mac无法运行XCode 4.5)。我的应用程序配置了4.3的iOS部署目标,6.0的基本SDK以及仅ARMv7的体系结构。XCode:苹果Mach-O链接器错误与新的iOS 6 ABAddressBook函数
我试图更新我以前的工作应用程序以请求访问用户的地址簿(现在是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/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)
我最好的猜测是的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;
}
我通过弱解决我的问题“与库链接二进制”我的目标构建的部分链接地址簿框架中添加AddressBook.framework
阶段设置(“可选”而不是“必需”)。
此外,我相信有一个XCode4.2错误,它复制设备目标。出于某种原因,选择重复后,我的应用程序能够编译(请参阅以下链接:How to access weak linked framework in iOS?)。
那是,如果你不框架链接到你的项目,你通常会得到错误的类型。所以,你可能导入了头文件(因此没有编译时错误),但是,你没有从TargetName->Build Phases->Link Binary With Libraries
我以前在我的项目中添加了“AddressBook.framework”和“AddressBookUI.framework”,因为我需要这两种方法才能在iOS 6 SDK发布之前访问应用中的用户联系人。我甚至删除并重新添加它们,因为我需要从iOS 6.0文件夹中专门添加它们。任何其他想法,@Valentin Radu? – JRoss
Build Settings中的基础SDK设置是什么? –
最新的iOS(iOS 6.0)@Valentin Radu – JRoss