iOS Unexpected platform condition (expected 'os', 'arch', or 'swift') - Reachability

喜欢而已 提交于 2019-12-13 12:32:10

问题


I just update my pods. after update Reachability causing an error

Unexpected platform condition (expected 'os', 'arch', or 'swift')

I tried to build and clean but it does not work. what's the solution?

Please help me to fix this. Thanks in advance.


回答1:


use this 1

#if (arch(i386) || arch(x86_64)) && os(iOS)

#endif



回答2:


You can try as Muhammad says.

I suggest the following code which is very easy to maintain. Copy paste the following code to a file and try yourself.

import Foundation
import SystemConfiguration

class Network {

    // Declarations
    static let shared = Network()


    // Check has Network
    func isConnected() -> Bool  {

        var zeroAddress = sockaddr_in()
        zeroAddress.sin_len = UInt8(MemoryLayout.size(ofValue: zeroAddress))
        zeroAddress.sin_family = sa_family_t(AF_INET)

        let defaultRouteReachability = withUnsafePointer(to: &zeroAddress) {
            $0.withMemoryRebound(to: sockaddr.self, capacity: 1) {zeroSockAddress in
                SCNetworkReachabilityCreateWithAddress(nil, zeroSockAddress)
            }
        }

        var flags = SCNetworkReachabilityFlags()
        if !SCNetworkReachabilityGetFlags(defaultRouteReachability!, &flags) {
            return false
        }
        let isReachable = (flags.rawValue & UInt32(kSCNetworkFlagsReachable)) != 0
        let needsConnection = (flags.rawValue & UInt32(kSCNetworkFlagsConnectionRequired)) != 0
        return (isReachable && !needsConnection)
    }

}

Create a swift file and put the above code on that file. Whenever you want to check the network status just use the following code

if Network.shared.isConnected() {

   print("Network available")
} else {

   print("Not connected")
}


来源:https://stackoverflow.com/questions/52523952/ios-unexpected-platform-condition-expected-os-arch-or-swift-reachabi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!