Send data to server whenever internet connection i

2019-05-03 20:18发布

I am developing an iOS app,

What i want to do is, whenever user turned on/off his internet from setting app, i want to set some notification to device.

In short, i want to send some data (stored in NSUserDefaults) to server whenever internet connection is available(assuming internet connection appears after 2 3 days)....possible?

Please help and thanks in advance.

3条回答
对你真心纯属浪费
2楼-- · 2019-05-03 20:47

Apple write an demo for this.Just search reachability in Xcode Document and APIs(or in iOS developer library).And choose sample code.

I'm afraid you must use background task.Look up background task guide.But I think it's a little abuse for just check network.

查看更多
一夜七次
3楼-- · 2019-05-03 20:55

Try this Apple example: https://developer.apple.com/library/ios/samplecode/Reachability/Introduction/Intro.html

If you want this to work when app in background try background task

If you what your app doesn't suspend in background look at this: http://www.raywenderlich.com/29948/backgrounding-for-ios

查看更多
来,给爷笑一个
4楼-- · 2019-05-03 21:09

You may check Internet connectivity via Reachability class while your app is running in foreground or background state.

But if your app is closed then you can't detect network connection within your app. So its not possible to generate any notification by detecting network connection while app is closed.

查看更多
登录 后发表回答