How to run a Background Task on iOS application when Internet connection is detected?

妖精的绣舞 提交于 2019-12-02 22:42:52

问题


I'm using a third party library "Reachability.swift"

https://github.com/ashleymills/Reachability.swift

Followed this blog post to identify network event using Notification Center, So the change in network event can be identified dynamically in the foreground

https://blog.pusher.com/handling-internet-connection-reachability-swift/

My Requirement:-

I need to run a background service that uses Alamofire(Information not needed for alamofire) to push the locally saved SQLite data to the server whenever internet connection status is Active

Important note:- iOS Application should not run in the foreground, everything should happen in the background

Please help me out to understand the topic, Thank in advance!


回答1:


You should fully read and understand Apple's excellent documentation on background execution: Background Execution

There are only a few application types that are allowed to run permanently in background mode:

  • Apps that play audible content to the user while in the background, such as a music player app
  • Apps that record audio content while in the background
  • Apps that keep users informed of their location at all times, such as a navigation app
  • Apps that support Voice over Internet Protocol (VoIP)
  • Apps that need to download and process new content regularly
  • Apps that receive regular updates from external accessories

Apps of those types must ask for specific permission to run in the background. Declaring a wrong type for your app may lead to app rejection by Apple.



来源:https://stackoverflow.com/questions/52473867/how-to-run-a-background-task-on-ios-application-when-internet-connection-is-dete

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