0

我有一个使用 Alamofire 和 FileKit 等库的 iOS 应用程序及其共享扩展的项目。一切都与以下完美配合Podfile

target 'myApp' do
  use_frameworks!
  pod 'BRYXBanner'
end
target 'myAppShareExtension' do
  use_frameworks!
  pod 'FileKit', '~> 4.0.1'
  pod 'Alamofire', '~> 4.4'
end

然后,我想使用SVProgressHUD. 首先,我只是将它添加到主应用程序中,一切都很好。当我想在扩展中使用它时,问题就开始了。从那时起,我多次更改 Podfile,但没有一个允许我在应用程序和扩展程序中都拥有它。更糟糕的是,我什至无法在主应用程序中再次使用它。一旦我将它添加到Podfile,我的应用程序就无法编译。甚至不能再编译了AlamofireFileKit

这是我的新 Podfile,它是唯一一个在pod install.

platform :ios, '10.2'
use_frameworks!
target 'myApp' do
       target 'myAppShareExtension' do
                pod 'SVProgressHUD', :git => 'https://github.com/SVProgressHUD/SVProgressHUD.git'
                pod 'Alamofire', '~> 4.0'
                pod 'FileKit', '~> 4.0.1'
       end
end

当我尝试编译时,我有以下错误,即使没有尝试导入 SVProgressHUD 也没有使用它:

'sharedApplication' is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead.

请注意,当我使用后一个 Podfile 时,我的扩展目标被命名Pods-myApp-myAppShareExtension,而它应该是Pods-myAppShareExtension这让我认为问题来自 podfile

如果您对 Podfile 语法、构建环境等有任何建议,请不要犹豫。我可以提供关于

编辑:请注意,我尝试了不同的构建设置选项,也许我在那里搞砸了。

4

1 回答 1

2

看到错误在哪里,你就会明白问题出在哪里。

#if !defined(SV_APP_EXTENSIONS)
    UIInterfaceOrientation orientation = UIApplication.sharedApplication.statusBarOrientation;
#else
    UIInterfaceOrientation orientation = CGRectGetWidth(self.frame) > CGRectGetHeight(self.frame) ? UIInterfaceOrientationLandscapeLeft : UIInterfaceOrientationPortrait;
#endif

你看到了SV_APP_EXTENSIONS吗?这意味着如果目标不是 App Extensions,它将编译上面的代码,如果是,它将编译下面的代码。所以现在,您需要它在您的 App Extension 目标中工作,您需要将预处理器宏添加到您的 App Extension 目标中。

在此处输入图像描述

于 2017-12-05T01:23:10.537 回答