我想在 iOS 5 上使用 Twitter 框架,但能够在旧操作系统中运行我的应用程序。
我在 Xcode 4.2 Target 设置中添加了弱引用框架(即设置“可选”标志)。基础 SDK 是 iOS 5,iOS 部署目标是 iOS 3.2。
接下来我尝试使用Twitter框架:
#import <Twitter/Twitter.h>
...
Class twClass = NSClassFromString(@"TWTweetComposeViewController");
if (!twClass) // Framework not available, older iOS
{
[self shareWithTwitterPriorIOS5];
return;
}
if ([TWTweetComposeViewController canSendTweet]) // Check if twitter is setup and reachable
{
TWTweetComposeViewController* twc = [[TWTweetComposeViewController alloc] init];
// [twc addURL:[NSURL URLWithString:@"http://mail.ru"]];
// [twc addImage:[UIImage imageNamed:@"Some image.png"]]
[twc setInitialText:textToShare];
[viewController presentViewController:twc animated:YES completion:^{
// Optional
}];
[twc release];
// Assume twc is ARC released or call [twc release];
}
else
{
// Twitter account not configured, inform the user
}
它在 iOS 5 模拟器上运行良好。一旦我尝试使用模拟器或具有较旧操作系统版本的真实设备,我就会收到错误“Twitter/Twitter.h”文件未找到(在编译时)。如果我删除“#import”指令,我会收到几个错误 TWTweetComposeViewController 类未找到。
如果我评论所有与 Twitter 相关的代码,则会收到链接器错误:“ld:未找到 Twitter 框架”。 ld 命令导致错误:
Ld /Users/mikhailkeskinov/Library/Developer/Xcode/DerivedData/Dictionary-eiyrziajmltuglfzgtnjxffkojwi/Build/Products/Debug-iphoneos/Dictionary.app/Dictionary normal armv6
cd /Developer/WorkShop/XDictionary/trunk
setenv IPHONEOS_DEPLOYMENT_TARGET 3.2
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 armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk -L/Users/mikhailkeskinov/Library/Developer/Xcode/DerivedData/Dictionary-eiyrziajmltuglfzgtnjxffkojwi/Build/Products/Debug-iphoneos "-L/Developer/WorkShop/XDictionary/trunk/Dictionary/Twitter+OAuth/Libraries & Headers" -F/Users/mikhailkeskinov/Library/Developer/Xcode/DerivedData/Dictionary-eiyrziajmltuglfzgtnjxffkojwi/Build/Products/Debug-iphoneos -filelist /Users/mikhailkeskinov/Library/Developer/Xcode/DerivedData/Dictionary-eiyrziajmltuglfzgtnjxffkojwi/Build/Intermediates/Dictionary.build/Debug-iphoneos/Dictionary.build/Objects-normal/armv6/Dictionary.LinkFileList -dead_strip -miphoneos-version-min=3.2 -lxml2 -framework AVFoundation -framework UIKit -framework Foundation -framework CoreGraphics -lOAuth -weak_framework Twitter -o /Users/mikhailkeskinov/Library/Developer/Xcode/DerivedData/Dictionary-eiyrziajmltuglfzgtnjxffkojwi/Build/Products/Debug-iphoneos/Dictionary.app/Dictionary
这里有什么问题吗?
5 小时后,大量愚蠢的文档阅读器,更改所有目标和项目设置等。我至少找到了解决方案。当你知道的时候,事实证明这很容易。也许,我的回答会拯救某人的一天。
正如您所看到的,真实设备目标(“mkeskinov 的 iPod”)增加了一倍。我从来不注意这个事实。看起来好像只是由于某些错误而翻倍了,但事实并非如此。如果您选择“产品\编辑方案”并打开目标列表(位于窗口顶部),您可以清楚地看到差异:
我需要做什么才能成功编译真实设备的应用程序 - 只需选择第二个选项。它将针对 iOS 5 进行编译,然后在具有 OS 4 的真实设备上运行。第一个选项意味着它将针对 iOS 4 进行编译,并且如果您有任何对 iOS 4 中未提供的框架的引用(没关系,弱引用)或强) - 你会得到编译时错误。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)