-4

I want to synchronize data with my App-Server whenever data has been saved to the local database (sqlite) on my mobile phone. I need a mechanism that automatically detects an internet connection in order to send the related saved data to my server at any time. That's how I want to realize an offline mode.

Which approaches can you recommend me? Are there any frameworks which do that job? In android I use syncAdapter, does Swift3 provides a similar framework or do I need to create an own solution?

Johannes N
  • 265
  • 3
  • 17
  • 1
    `SCNetworkReachability` can be used to detect status and changes of the network connectivity. https://github.com/ashleymills/Reachability.swift is a well-known Swift wrapper. You'll also find many Q&A about SCNetworkReachability here on SO. – Martin R Dec 07 '16 at 06:26
  • Possible duplicate of [Sync adapter on IOS - My app sync contact with my server](http://stackoverflow.com/questions/22981812/sync-adapter-on-ios-my-app-sync-contact-with-my-server) – Fay007 Dec 07 '16 at 06:28
  • Possible duplicate of [Create equivalent of Androids sync adapter on iOS](http://stackoverflow.com/questions/8406736/create-equivalent-of-androids-sync-adapter-on-ios) – Johannes N Dec 07 '16 at 17:26
  • Possible duplicate of [How to check for an active Internet connection on iOS or OSX?](http://stackoverflow.com/questions/1083701/how-to-check-for-an-active-internet-connection-on-ios-or-osx) – Johannes N Feb 06 '17 at 22:25

1 Answers1

1

Steps to do it-

  1. Use pod 'ReachabilitySwift' in your pod file
  2. In 'AppDelegate' import ReachabilitySwift
  3. Write following code in AppDelegate

     var reachabilityManager:ReachabilityManager = ReachabilityManager.sharedInstance
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        NetworkActivityIndicatorManager.shared.isEnabled = true
        reachabilityManager.initRechabilityMonitor()
        return true
    }
    
    func reachabilityStatusChangeHandler(_ reachability: Reachability) {
        if reachability.isReachable {
            print("isReachable")
        } else {
            print("notReachable")
        }
    }