ios - 在 Swift 5 中使用可达性

标签 ios swift cocoapods reachability reachability-swift

<分区>

我按照本教程尝试在我的项目中安装并使用可达性 (https://medium.freecodecamp.org/how-to-handle-internet-connection-reachability-in-swift-34482301ea57)

它表明它已全部安装,但我的 Import 语句中仍然出现错误。

下图显示了 Podfile、pod 安装过程、项目目标名称和错误。

知道我遗漏了什么吗?我需要检测连接类型(3G、4G、Wifi 等)

NetworkStatus.swift header

import Foundation
import Reachability //No such module 'Reachability'

播客文件

Dans-MacBook-Pro:gnccapp danpalmer$ cat Podfile
# Uncomment the next line to define a global platform for your project
  platform :ios, '12.2'

target 'gnccapp' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for gnccapp
  pod 'ReachabilitySwift'
  pod 'Alamofire'

end

Pod的安装过程

Dans-MacBook-Pro:gnccapp danpalmer$ pod install
Analyzing dependencies
Setting up CocoaPods master repo
  $ /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress
  Cloning into 'master'...
  remote: Enumerating objects: 317, done.        
  remote: Counting objects: 100% (317/317), done.        
  remote: Compressing objects: 100% (256/256), done.        
  remote: Total 3118566 (delta 105), reused 136 (delta 45), pack-reused 3118249        
  Receiving objects: 100% (3118566/3118566), 646.21 MiB | 1.59 MiB/s, done.
  Resolving deltas: 100% (1856966/1856966), done.
  Checking out files: 100% (326428/326428), done.

CocoaPods 1.7.0.rc.1 is available.
To update use: `sudo gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.7.0.rc.1

Setup completed
Downloading dependencies
Installing ReachabilitySwift (4.3.1)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `GNCC.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

[!] Automatically assigning platform `ios` with version `12.2` on target `gnccapp` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.
Dans-MacBook-Pro:gnccapp danpalmer$ ls -l
total 16
drwxr-xr-x@  6 danpalmer  staff  192 May  6 11:50 GNCC.xcodeproj
drwxr-xr-x   3 danpalmer  staff   96 May  6 11:46 GNCC.xcworkspace
-rw-r--r--   1 danpalmer  staff  279 May  6 11:35 Podfile
-rw-r--r--   1 danpalmer  staff  309 May  6 11:46 Podfile.lock
drwxr-xr-x   8 danpalmer  staff  256 May  6 11:46 Pods
drwxr-xr-x   4 danpalmer  staff  128 May  3 10:39 fonts
drwxr-xr-x  20 danpalmer  staff  640 May  6 11:52 gnccapp
Dans-MacBook-Pro:gnccapp danpalmer$ vi Podfile
Dans-MacBook-Pro:gnccapp danpalmer$ pod install
Analyzing dependencies
Downloading dependencies
Installing Alamofire (4.8.2)
Using ReachabilitySwift (4.3.1)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.

最佳答案

确保您打开的文件以 .xc​​workspace 而不是 .xcodeproj 结尾

关于ios - 在 Swift 5 中使用可达性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56010939/

相关文章:

iOS - 如何将信息从 VIEW 传递到 Controller?

ios - 无效的权利 Xcode

ios - 在 Swift 4 中调用刷新数据函数时 UIViewController 刷新失败

ios - 检查 textField.text isEqualToString

objective-c - Segue 使我的程序崩溃。与我的 NavigationController 和 TabBarViewController 有关

objective-c - 如何让 podspec 尊重 "head:"论点?

json - fatal error : Index out of range (while trying to load an image to a table view)

arrays - 为什么这个简单的数组访问在 Swift 中不起作用?

ruby - OS X 优胜美地 : Impossible to install cocoapods

swift - 由于缺少依赖项,Moscapsule 阻止为 watchOS 构建应用程序