context.save() only inserted managed objects

In core data stack with SQLite, when terminating an app I would like to persist managed objects in viewContext serving whatever viewControllers. The difficult part is in doing so for updated and deleted managed objects only when accessible is cloud server where the true copy of these objects' info stays. In other words, if there is no connection to cloud server, I only persist inserted objects in a viewContext. is there a solution for this logic?