ios - 如何在 iOS 应用程序及其扩展中使用 SVProgressHUD

标签 ios xcode podfile svprogresshud

我有一个 iOS 应用程序项目及其使用 Alamofire 和 FileKit 等库的共享扩展。一切都与以下 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 语法、构建环境等有任何建议,请不要犹豫。我可以提供有关

的其他信息

编辑:请注意,我尝试了不同的build设置选项,也许我在那里弄乱了一些东西。

最佳答案

看到哪里出错了,就明白问题出在哪里了。

#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 目标。

enter image description here

关于ios - 如何在 iOS 应用程序及其扩展中使用 SVProgressHUD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43734371/

相关文章:

iphone - SQLCipher "sqlite_3key"归档和分析警告,调试无警告

swift - CocoaPods 的 Xcode 8.3 XCtest 问题

iphone - TWTweetComposeViewController 不允许编辑

ios - 来自 IOS Xcode 的 Azure 推送通知错误

ios - 如何知道 ViewModel 中单个 map 的完成?

iphone - 当 AVAudioPlayer 循环回到开头时如何得到通知?

ios - swift 3 : Playing Audio based on a string variable

ios - 如何在 iOS 应用程序中将应用程序图标与启动图像分开

ios - 为什么Xcode方案中的React(missing)生成目标列表?

ios - Flutter:CocoaPods 的 specs 存储库过时,无法满足依赖关系