如何在iOS中访问弱链接框架? [英] How to access weak linked framework in iOS?

查看:133
本文介绍了如何在iOS中访问弱链接框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用适用于iOS 5的Twitter框架,但能够在较旧的操作系统中运行我的应用程序。

I want to use Twitter framework for iOS 5, but be able to run my app in older OS.

我添加了弱引用框架(即设置可选标志)在Xcode 4.2目标设置。 Base SDK是iOS 5,iOS部署Target是iOS 3.2。

I added weak referenced framework (i.e. set "optional" flag) in Xcode 4.2 Target settings. Base SDK is iOS 5, iOS deployment Target is iOS 3.2.

接下来,我尝试使用Twitter框架:

Next, I try to use Twitter framework:

#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类未找到。

It run well on iOS 5 simulator. As soon as I try to use simulator or real device with older OS version, I get error "Twitter/Twitter.h" file not found (in compile time). If I remove "#import" directive, I get a couple of errors TWTweetComposeViewController class not found.

如果我评论所有与Twitter相关的代码,我会收到链接器错误: ld:框架未找到Twitter。 Ld命令导致错误:

If I comment all twitter-related code, I get linker error: "ld: framework not found Twitter". Ld command caused error:

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个小时后,吨傻文档阅读器,改变所有目标&项目设置等我至少解决了。事实证明,当你知道它时,这很容易。也许,我的答案将节省一些人的日子。

After 5 hours, tons silly documentation reader, changing all target & project settings etc. I at least come to solution. Turns out it is pretty easy, when you know it. Probably, my answer will save somebody's day.

如你所见,真实设备目的地(mkeskinov的iPod)增加了一倍。我从不关注这个事实。它似乎只是因为某些错误而翻了一番,但事实并非如此。如果您选择Product\Edit Schemes&打开目的地列表(在窗口顶部),您可以清楚地看到差异:

As you can see, real device destination ("mkeskinov's iPod") doubled. I never pay attention at this fact. It looks like it just doubled by some mistake, but it is not. If you select "Product\Edit Schemes" & open Destination list (on the top of window), you can clearly see the difference:

成功编译真实设备的应用程序需要做什么 - 只需选择第二个选项。它将针对iOS 5进行编译,然后在具有OS 4的真实设备上运行。第一个选项意味着它将针对iOS 4进行编译,并且如果您对Frameworks有任何引用,这在iOS 4中没有呈现(没关系,弱引用或者强烈 - 你得到编译时错误。

What I need to do to successfully compile app for real device - just select second option. It will compile for iOS 5 and then run on real device with OS 4. First option means that it will be compile for iOS 4, and if you have any references to Frameworks, which is not presented in iOS 4 (never mind, weak references or strong) - you get compile time error.

这篇关于如何在iOS中访问弱链接框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆