{"id":10258,"date":"2023-06-23T01:43:43","date_gmt":"2023-06-23T08:43:43","guid":{"rendered":"https:\/\/www.couchbase.com\/developers\/tutorials\/background-refresh-ios-uikit\/"},"modified":"2023-06-23T01:43:43","modified_gmt":"2023-06-23T08:43:43","slug":"background-refresh-ios-uikit","status":"publish","type":"tutorials","link":"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/background-refresh-ios-uikit\/","title":{"rendered":"Tutorial Background App Refresh in iOS with UIKit and Swift"},"content":{"rendered":"\n<h3 id=\"h-introduction\" class=\"wp-block-heading\">Introduction<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The ability for a mobile app to run in the background is an important element of the life cycle of a mobile application. The ability to sync data while in the background would be useful in several scenarios. Background support is platform specific and is hence not built into Couchbase Lite. However, one can easily leverage the various platform specific backgrounding capabilities to perform data sync over Couchbase Mobile.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This tutorial will demonstrate how to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Configure your iOS app for Background Fetch support<\/li>\n\n\n<li>Setup your app to do a one-shot sync with Couchbase Sync Gateway while in the background<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">We will be using a Swift App as an example of a Couchbase Lite enabled client.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">More information on <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/2.0\/guides\/sync-gateway\/index.html\">Sync Gateway<\/a> can be found in our documentation site.<\/p>\n\n\n\n<h3 id=\"h-prerequisites\" class=\"wp-block-heading\">Prerequisites<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This tutorial assumes familiarity with building swift apps with Xcode and with Couchbase Lite.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\n<p>You must have completed the &#8220;user profile&#8221; tutorial on <strong>sync<\/strong>. If you haven&#8217;t already done so, please complete the following tutorial first<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.couchbase.com\/tutorials\/userprofile-couchbase-mobile\/sync\/userprofile\/userprofile_sync.html\">Fundamentals of Sync<\/a> using Couchbase Lite and Sync Gateway<\/li>\n<\/ul>\n<\/li>\n\n\n<li>\n<p>iOS (Xcode 11+)<\/p>\n<ul>\n<li>Download latest version from the <a href=\"https:\/\/itunes.apple.com\/us\/app\/xcode\/id497799835?mt=12\">Mac App Store<\/a><\/li>\n<li>NOTE: If you are on an older version of Xcode that you must retain for your other development needs, you can make a copy of your existing version of Xcode and install Xcode 10. So you can have multiple versions of Xcode on your Mac.<\/li>\n<\/ul>\n<\/li>\n\n\n<li>\n<p>git (Optional) This is required if you would prefer to pull the source code from GitHub repo.<\/p>\n<ul>\n<li>Create a <a href=\"https:\/\/github.com\">free github account<\/a> if you don&#8217;t already have one<\/li>\n<li>git can be downloaded from <a href=\"https:\/\/git-scm.com\/book\/en\/v2\/Getting-Started-Installing-Git\">git-scm.org<\/a><\/li>\n<\/ul>\n<\/li>\n\n\n<li>\n<p>curl HTTP client<\/p>\n<ul>\n<li>You could use any HTTP client of your choice. But we will use <em>curl<\/em> in our tutorial. Download latest version from <a href=\"https:\/\/curl.haxx.se\/download.html\">curl website<\/a><\/li>\n<\/ul>\n<\/li>\n\n<\/ul>\n\n\n\n<h3 id=\"h-system-overview\" class=\"wp-block-heading\">System Overview<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We will be working with a simple &#8220;User Profile&#8221; app which we introduced in the <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/2.0\/userprofile_basic.html\">Fundamentals Tutorial<\/a> and extended to support data sync capabilities in the <a href=\"https:\/\/docs.couchbase.com\/tutorials\/userprofile-couchbase-mobile\/sync\/userprofile\/userprofile_sync.html\">Sync Tutorial<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this tutorial, we will be extending that app to support data sync when in the background.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The app does the following<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Allows users to log in and create or update his\/her user profile information. The user profile view is automatically updated everytime the profile information changes in the underlying database<\/li>\n\n\n<li>The user profile information is synced with a remote Sync Gateway which then syncs it to other devices (subject to access control and routing configurations specified in the <code>sync function<\/code>)<\/li>\n\n\n<li>When the app is woken up in the <em>background<\/em>, it does a one-shot replication with the remote Sync Gateway<\/li>\n\n<\/ul>\n\n\n\n<h3 id=\"h-app-installation\" class=\"wp-block-heading\">App Installation<\/h3>\n\n\n\n<h4 id=\"h-fetching-app-source-code\" class=\"wp-block-heading\">Fetching App Source Code<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">You have two options<\/p>\n\n\n\n<h5 id=\"h-option-1-git-clone\" class=\"wp-block-heading\">Option 1 : Git Clone<\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Clone the <em>backgroundfetch<\/em> branch of the <code>User Profile Demo<\/code> project from GitHub. Type the following command in your terminal<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-shell\"><code>  git clone -b backgroundfetch https:\/\/github.com\/couchbaselabs\/userprofile-couchbase-mobile.git\n<\/code><\/pre>\n\n\n\n<h5 id=\"h-option-2-download--zip\" class=\"wp-block-heading\">Option 2 : Download .zip<\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A download for the <a href=\"https:\/\/github.com\/couchbaselabs\/userprofile-couchbase-mobile\/archive\/backgroundfetch.zip\">User Profile Demo project<\/a> can be found in our documentation site.<\/li>\n\n<\/ul>\n\n\n\n<h3 id=\"h-installing-couchbase-lite-framework\" class=\"wp-block-heading\">Installing Couchbase Lite Framework<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Next, we will download the latest version of Couchbase Lite 2.x framework. The Couchbase Lite iOS framework is <a href=\"https:\/\/developer.couchbase.com\/documentation\/mobile\/current\/couchbase-lite\/swift.html\">distributed<\/a>via Cocoapods, Carthage or you can download the pre-built framework. In our example, we will be downloading the pre-built version of the framework. For this, type the following in the command terminal<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-shell\"><code>  cd \/path\/to\/UserProfileDemo\/content\/modules\/userprofile\/examples\n\n  sh install_11.sh\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">let&#8217;s verify the installation<\/p>\n\n\n\n<h4 id=\"h-try-it-out-by-building-and-running\" class=\"wp-block-heading\">Try it Out by Building and Running<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open the <code>UserProfileDemo.xcodeproj<\/code>. The project would be located at <code>\/path\/to\/UserProfileDemo\/content\/modules\/userprofile\/examples<\/code><\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-shell\"><code>open UserProfileDemo.xcodeproj\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Build and run the project in the simulator using Xcode<\/li>\n\n\n<li>Verify that you see the login screen<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/login_screen.png\" alt=\"User Profile Login Screen Image\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\"login_screen.png\" alt=\"User Profile Login Screen Image\"><\/p>\n\n\n\n<h3 id=\"h-sync-gateway-2-x-installation\" class=\"wp-block-heading\">Sync Gateway 2.x Installation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Follow the steps outlined in the <a href=\"https:\/\/docs.couchbase.com\/tutorials\/userprofile-couchbase-mobile\/sync\/userprofile\/userprofile_sync.html#sync-gateway-2-0-installationto\">Sync Tutorial<\/a> install the Sync Gateway on localhost running in walrus mode.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note that the walrus must is a development-only mode used for testing\/demonstration purposes. It must be <strong>never<\/strong> used in production.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, let&#8217;s verify the installation<\/p>\n\n\n\n<h4 id=\"h-try-it-out-in-the-browser\" class=\"wp-block-heading\">Try it Out in the Browser<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open a browser and enter <code>http:\/\/localhost:4984<\/code> in the address bar<\/li>\n\n\n<li>You should see a message similar one below<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-shell\"><code>{&quot;couchdb&quot;:&quot;Welcome&quot;,&quot;vendor&quot;:{&quot;name&quot;:&quot;Couchbase Sync Gateway&quot;,&quot;version&quot;:&quot;2.0&quot;},&quot;version&quot;:&quot;Couchbase Sync Gateway\/2.0.0(832;2d8a6c0)&quot;}\n<\/code><\/pre>\n\n\n\n<h3 id=\"h-data-model\" class=\"wp-block-heading\">Data Model<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">There are two documents &#8211; the &#8220;user profile&#8221; type document and &#8220;university&#8221; type document. We will use the same data model as discussed in <a href=\"https:\/\/docs.couchbase.com\/tutorials\/userprofile-couchbase-mobile\/sync\/userprofile\/userprofile_sync.html#data-model\">data model section<\/a> of the Sync tutorial.<\/p>\n\n\n\n<h3 id=\"h-configuring-app-for-background-app-refresh\" class=\"wp-block-heading\">Configuring App for Background App Refresh<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">iOS supports several backgrounding models. One such option is Background App Refresh. According to <a href=\"https:\/\/developer.apple.com\/documentation\/uikit\/core_app\/managing_your_app_s_life_cycle\/preparing_your_app_to_run_in_the_background\/updating_your_app_with_background_app_refresh\">Apple docs<\/a>, <em>Background App Refresh<\/em> lets your app run periodically in the background so that it can update its content. The iOS system uses its discretion to determine when to wake up and run your app, typically by learning your app usage over time. In other words, there is no guarantee that your app will have an opportunity to run in the background. Even when provided with the opportunity, the app gets a finite amount of time to run.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\n<p>Open the &#8220;capabilities&#8221; tab in the <strong>UserProfileDemo.xcodeproj<\/strong> file. Note that &#8220;Background Fetch&#8221; is enabled under the &#8220;Background models&#8221; tab\n<img decoding=\"async\" src=\".\/bg_modes.png\" alt=\"Background Modes\"><\/p>\n<\/li>\n\n\n<li>\n<p>Open the <strong>AppDelegate.swift<\/strong> file and locate the <code>application:didFinishLaunchingWithOptions()<\/code> function.<\/p>\n<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-swift\"><code>func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -&gt; Bool {\n    \/\/ Override point for customization after application launch.\n    self.loadLoginViewController()\n    UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)\n    return true\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Here we specify the periodicity at which the app should be woken up. We use a value of <em>UIApplicationBackgroundFetchIntervalMinimum<\/em> which is the smallest fetch interval supported by the system<\/li>\n\n<\/ul>\n\n\n\n<h3 id=\"h-implementing-the-background-fetch-callback\" class=\"wp-block-heading\">Implementing the Background Fetch callback<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open the <strong>AppDelegate.swift<\/strong> file and locate the <code>application:performFetchWithCompletionHandler()<\/code> function. This callback function is invoked by the system everything the app is launched in the background.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-swift\"><code>\/\/ Support for background fetch\nfunc application( _ application: UIApplication,\n                    performFetchWithCompletionHandler\n    completionHandler: @escaping (UIBackgroundFetchResult) -&gt; Void) {\n    print(#function)\n    \n    \/\/ Do a one shot replication\n    self.cbMgr.startOneShotPullReplicationForCurrentUser { (status) in\n        completionHandler(.newData) \/\/ &lt;1&gt;\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">&lt;1&gt; Invoke function on to do a one-shot replication with the Sync Gateway. Everytime the app is launched, all pending changes with the remote Sync Gateway will be synched up<\/p>\n\n\n\n<h3 id=\"h-implementing-the-oneshot-replication\" class=\"wp-block-heading\">Implementing the One-shot replication<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Setting up the app for one-shot replication is very similar to continuous replication that was discussed in the <a href=\"https:\/\/docs.couchbase.com\/tutorials\/userprofile-couchbase-mobile\/sync\/userprofile\/userprofile_sync.html#starting-replication\">Sync tutorial<\/a>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open the <strong>DatabaseManager.swift<\/strong> file and locate the <code>startOneShotPullReplicationForCurrentUser()<\/code> function.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-swift\"><code>func startOneShotPullReplicationForCurrentUser(completionHandler:@escaping(_ doneStatus:Bool)-&gt;Void) {\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Let&#8217;s examine the replicator configuration<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-swift\"><code>let dbUrl = remoteUrl.appendingPathComponent(kDBName)\nlet config = ReplicatorConfiguration.init(database: db, target: URLEndpoint.init(url:dbUrl))\nconfig.continuous =  false \/\/ &lt;1&gt;\nconfig.replicatorType = .pull \/\/ &lt;2&gt;\nconfig.authenticator =  BasicAuthenticator(username: user, password: password)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">&lt;1&gt; The&#8221;continuous&#8221; mode is set to &#8220;false&#8221; in the Replicator configuration indicating that this is a one-shot replication. In one-shot mode, the replicator goes into idle state once all pending changes are synced\n&lt;2&gt; The &#8220;replicationType&#8221; is set to pull-only in the Replicator configuration indicating that the app will only pull changes from remote client when in the background.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The rest of the configuration is as in the continuous replication case.<\/p>\n\n\n\n<h3 id=\"h-exercises\" class=\"wp-block-heading\">Exercises<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Before proceeding with the exercises in this section, complete the exercises in the <a href=\"https:\/\/docs.couchbase.com\/tutorials\/userprofile-couchbase-mobile\/sync\/userprofile\/userprofile_sync.html#exercises\">Sync tutorial<\/a> to verify that you can sync changes between the app and Sync Gateway with the app in the foreground.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the following exercise, we will observe how changes made on Sync Gateway are fetched by the iOS app in the background<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The app must be running in the simulator with the <em>xcode debugger attached<\/em>. This is important as we will use the xcode debugger for simulating background fetches.<\/li>\n\n\n<li>Push the app in the simulator to the background. Typically you can do it with the Shift-Cmd-H key combination<\/li>\n\n\n<li>Clear the debug console logs in xcode. This will make it easier to identify what goes on when the app is launched in the background<\/li>\n\n\n<li>Open the command terminal and issue the following <code>curl<\/code> command to get the user profile document on the Sync Gateway via GET Document REST API<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-swift\"><code>curl -X GET \n  http:\/\/localhost:4985\/userprofile\/user::demo@example.com \n  -H &#039;Accept: application\/json&#039; \n  -H &#039;Cache-Control: no-cache&#039; \n  -H &#039;Content-Type: application\/json&#039;\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Your response should look something like the response below. The exact contents depends on the user profile that you provided via your mobile app.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-swift\"><code>{\n  &quot;_attachments&quot;: {\n    &quot;blob_\/image&quot;: {\n      &quot;content_type&quot;: &quot;image\/jpeg&quot;,\n      &quot;digest&quot;: &quot;sha1-9OHO0QIk+kREiOaoMlrEg\/jU4zU=&quot;,\n      &quot;length&quot;: 15110,\n      &quot;revpos&quot;: 1,\n      &quot;stub&quot;: true\n    }\n  },\n  &quot;_id&quot;: &quot;user::demo@example.com&quot;,\n  &quot;_rev&quot;: &quot;1-0b9e3efa5ec1b1596564c4db34ba28d4e618f9c5&quot;,\n  &quot;address&quot;: &quot;&quot;,\n  &quot;email&quot;: &quot;demo@example.com&quot;,\n  &quot;image&quot;: {\n    &quot;@type&quot;: &quot;blob&quot;,\n    &quot;content_type&quot;: &quot;image\/jpeg&quot;,\n    &quot;digest&quot;: &quot;sha1-9OHO0QIk+kREiOaoMlrEg\/jU4zU=&quot;,\n    &quot;length&quot;: 15110\n  },\n  &quot;name&quot;: &quot;&quot;,\n  &quot;type&quot;: &quot;user&quot;\n}\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In the command terminal, issue the following command to update the user profile document on the Sync Gateway<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code language-swift\"><code>curl -X PUT \n  &#039;http:\/\/localhost:4985\/userprofile\/user::demo@example.com?rev=1-0b9e3efa5ec1b1596564c4db34ba28d4e618f9c5&#039; \n  -H &#039;Accept: application\/json&#039; \n  -H &#039;Cache-Control: no-cache&#039; \n  -H &#039;Content-Type: application\/json&#039; \n  -d &#039;{\n  &quot;address&quot;: &quot;101 Main Street&quot;,\n  &quot;email&quot;: &quot;demo@example.com&quot;,\n  &quot;image&quot;: {\n    &quot;@type&quot;: &quot;blob&quot;,\n    &quot;content_type&quot;: &quot;image\/jpeg&quot;,\n    &quot;digest&quot;: &quot;sha1-S8asPSgzA+F+fp8\/2DdIy4K+0U8=&quot;,\n    &quot;length&quot;: 14989\n  },\n  &quot;name&quot;: &quot;priya Rajagopal&quot;,\n  &quot;type&quot;: &quot;user&quot;,\n  &quot;university&quot;: &quot;British Institute in Paris, University of London&quot;\n}&#039;\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Launch the iOS app in the background. You will simulate this through the Xcode Debug menu to &#8220;Simulate Background Fetch&#8221;<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/simulate_bg_fetch.png\" alt=\"Simulate Background Fetch\"><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Observe the console logs. You would see a set of messages indicating that the app has pulled the latest changes from the Sync Gateway<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/bg_console_logs.png\" alt=\"Background Fetch Logs\"><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\n<p>Stop the Sync Gateway<\/p>\n<\/li>\n\n\n<li>\n<p>Launch the app in the foreground. The user profile doc that was synced in the background will be displayed.<\/p>\n<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/relaunch_app.png\" alt=\"App Launched into foreground\"><\/p>\n\n\n\n<h3 id=\"h-learn-more\" class=\"wp-block-heading\">Learn More<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Congratulations on completing this tutorial!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This tutorial walked you through an example of how to synchronize data between Sync Gateway and Couchbase Lite enabled mobile app running in the background.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check out the following links for further details<\/p>\n\n\n\n<h4 id=\"h-further-reading\" class=\"wp-block-heading\">Further Reading<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.apple.com\/library\/archive\/documentation\/iPhone\/Conceptual\/iPhoneOSProgrammingGuide\/BackgroundExecution\/BackgroundExecution.html\">Apple Backgrounding Support<\/a><\/li>\n\n\n<li><a href=\"https:\/\/blog.couchbase.com\/data-replication-couchbase-mobile\/\">Overview of Replication Protocol 2.0<\/a><\/li>\n\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Introduction The ability for a mobile app to run in the background is an important element of the life cycle of a mobile application. The ability to sync data while in the background would be useful in several scenarios. Background support is platform specific and is hence not built into Couchbase Lite. However, one can [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false,"inline_featured_image":false,"_acf":"","footnotes":""},"tutorial-languages":[594],"tutorial-tags":[590,596],"tutorial-technologies":[585,597],"tutorial-types":[555],"class_list":["post-10258","tutorials","type-tutorials","status-publish","hentry","tutorial-languages-swift","tutorial-tags-ios","tutorial-tags-uikit","tutorial-technologies-mobile","tutorial-technologies-sync-gateway","tutorial-types-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v28.8 (Yoast SEO v28.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Tutorial Background App Refresh in iOS with UIKit and Swift - Couchbase<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/background-refresh-ios-uikit\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Tutorial Background App Refresh in iOS with UIKit and Swift\" \/>\n<meta property=\"og:description\" content=\"Introduction The ability for a mobile app to run in the background is an important element of the life cycle of a mobile application. The ability to sync data while in the background would be useful in several scenarios. Background support is platform specific and is hence not built into Couchbase Lite. However, one can [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/background-refresh-ios-uikit\/\" \/>\n<meta property=\"og:site_name\" content=\"Couchbase\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Couchbase\/\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/10\/Cloud-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2548\" \/>\n\t<meta property=\"og:image:height\" content=\"1171\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@couchbase\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/developers\\\/tutorials\\\/background-refresh-ios-uikit\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/developers\\\/tutorials\\\/background-refresh-ios-uikit\\\/\",\"name\":\"Tutorial Background App Refresh in iOS with UIKit and Swift - Couchbase\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/#website\"},\"datePublished\":\"2023-06-23T08:43:43+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/developers\\\/tutorials\\\/background-refresh-ios-uikit\\\/#breadcrumb\"},\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/developers\\\/tutorials\\\/background-refresh-ios-uikit\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/developers\\\/tutorials\\\/background-refresh-ios-uikit\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.couchbase.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tutorial Background App Refresh in iOS with UIKit and Swift\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/#website\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/\",\"name\":\"Couchbase\",\"description\":\"The Operational Data Platform for AI\u2122\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/#organization\"},\"alternateName\":\"Couchbase, Inc.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/#organization\",\"name\":\"Couchbase\",\"alternateName\":\"Couchbase, Inc.\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Couchbase_Logo_Couchbase_Token_Red-1.png\",\"contentUrl\":\"https:\\\/\\\/www.couchbase.com\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Couchbase_Logo_Couchbase_Token_Red-1.png\",\"width\":1129,\"height\":1129,\"caption\":\"Couchbase\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/fr\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Couchbase\\\/\",\"https:\\\/\\\/x.com\\\/couchbase\",\"https:\\\/\\\/www.youtube.com\\\/c\\\/CouchbaseServer\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/couchbase\\\/\",\"https:\\\/\\\/github.com\\\/couchbase\\\/\",\"https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/Couchbase,_Inc.\"],\"description\":\"Couchbase is a database software company headquartered in San Jose, California, providing an operational data platform for AI used by hundreds of global enterprises.\",\"legalName\":\"Couchbase, Inc.\",\"foundingDate\":\"2011-01-01\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Tutorial Background App Refresh in iOS with UIKit and Swift - Couchbase","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/background-refresh-ios-uikit\/","og_locale":"fr_FR","og_type":"article","og_title":"Tutorial Background App Refresh in iOS with UIKit and Swift","og_description":"Introduction The ability for a mobile app to run in the background is an important element of the life cycle of a mobile application. The ability to sync data while in the background would be useful in several scenarios. Background support is platform specific and is hence not built into Couchbase Lite. However, one can [&hellip;]","og_url":"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/background-refresh-ios-uikit\/","og_site_name":"Couchbase","article_publisher":"https:\/\/www.facebook.com\/Couchbase\/","og_image":[{"width":2548,"height":1171,"url":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/10\/Cloud-2.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_site":"@couchbase","twitter_misc":{"Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/background-refresh-ios-uikit\/","url":"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/background-refresh-ios-uikit\/","name":"Tutorial Background App Refresh in iOS with UIKit and Swift - Couchbase","isPartOf":{"@id":"https:\/\/www.couchbase.com\/fr\/#website"},"datePublished":"2023-06-23T08:43:43+00:00","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/background-refresh-ios-uikit\/#breadcrumb"},"inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/background-refresh-ios-uikit\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/fr\/developers\/tutorials\/background-refresh-ios-uikit\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/"},{"@type":"ListItem","position":2,"name":"Tutorial Background App Refresh in iOS with UIKit and Swift"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/fr\/#website","url":"https:\/\/www.couchbase.com\/fr\/","name":"Couchbase","description":"The Operational Data Platform for AI\u2122","publisher":{"@id":"https:\/\/www.couchbase.com\/fr\/#organization"},"alternateName":"Couchbase, Inc.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/fr\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/fr\/#organization","name":"Couchbase","alternateName":"Couchbase, Inc.","url":"https:\/\/www.couchbase.com\/fr\/","logo":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/www.couchbase.com\/fr\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/11\/Couchbase_Logo_Couchbase_Token_Red-1.png","contentUrl":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/11\/Couchbase_Logo_Couchbase_Token_Red-1.png","width":1129,"height":1129,"caption":"Couchbase"},"image":{"@id":"https:\/\/www.couchbase.com\/fr\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Couchbase\/","https:\/\/x.com\/couchbase","https:\/\/www.youtube.com\/c\/CouchbaseServer","https:\/\/www.linkedin.com\/company\/couchbase\/","https:\/\/github.com\/couchbase\/","https:\/\/en.wikipedia.org\/wiki\/Couchbase,_Inc."],"description":"Couchbase est une soci\u00e9t\u00e9 de logiciels de bases de donn\u00e9es dont le si\u00e8ge social est situ\u00e9 \u00e0 San Jose, en Californie, et qui fournit une plateforme op\u00e9rationnelle de donn\u00e9es pour l\u2019IA utilis\u00e9e par des centaines d\u2019entreprises mondiales.","legalName":"Couchbase, Inc.","foundingDate":"2011-01-01"}]}},"acf":[],"permalink_manager":null,"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/tutorials\/10258","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/tutorials"}],"about":[{"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/types\/tutorials"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/tutorials\/10258\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/media?parent=10258"}],"wp:term":[{"taxonomy":"tutorial-languages","embeddable":true,"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/tutorial-languages?post=10258"},{"taxonomy":"tutorial-tags","embeddable":true,"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/tutorial-tags?post=10258"},{"taxonomy":"tutorial-technologies","embeddable":true,"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/tutorial-technologies?post=10258"},{"taxonomy":"tutorial-types","embeddable":true,"href":"https:\/\/www.couchbase.com\/fr\/wp-json\/wp\/v2\/tutorial-types?post=10258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}