Using Simple Ping in swift (iOS)

后端 未结 1 457
囚心锁ツ
囚心锁ツ 2021-01-22 00:27

I\'m trying to use Apple\'s class: Simple Ping, but I can\'t get this working.

When I\'m running example mac os x project it\'s working:

2015-06-1

相关标签:
1条回答
  • 2021-01-22 00:39

    Not sure why this doesn't work, but you can call the ping method yourself once the address is resolved.

    A variable to tell you that you can start pinging:

    var canStartPinging = false
    

    The code that calls the ping:

    let pinger = SimplePing(hostName: "www.apple.com")
    pinger.delegate = self;
    pinger.start()
    
    do {
        if (canStartPinging) {
            pinger.sendPingWithData(nil)
        }
        NSRunLoop.currentRunLoop().runMode(NSDefaultRunLoopMode, beforeDate: NSDate.distantFuture() as! NSDate)
    } while(pinger != nil)
    

    The SimplePing delegate method to wait for before you can start pinging:

    func simplePing(pinger: SimplePing!, didStartWithAddress address: NSData!) {
        println("didStartWithAddress")
        canStartPinging = true
    }
    
    0 讨论(0)
提交回复
热议问题