Send data to server whenever internet connection is available iOS

北战南征 提交于 2019-12-07 07:14:48

问题


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.


回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/35124815/send-data-to-server-whenever-internet-connection-is-available-ios

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