{"action":"created","comment":{"url":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/comments/52435122","id":52435122,"diff_hunk":"@@ -160,13 +167,9 @@ - (void)addTodoButtonTap:(NSObject *)sender {\n -(IBAction)replicateTapped:(id)sender {\n     NSLog(@\"Replicate\");\n \n-    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{\n-        [self.todoReplicator sync];\n-        dispatch_async(dispatch_get_main_queue(), ^{\n-            [self reloadTasks];\n-            [self.tableView reloadData];\n-        });\n-    });\n+    [self.todoReplicator syncInBackgroundWithCompletionHandler:^{\n+        [self toggleCompletedShown:nil];","path":"Project/Project/CDTViewController.m","position":33,"original_position":33,"commit_id":"18a8b2d5e569b407158f62e7c20220041a4470c3","original_commit_id":"18a8b2d5e569b407158f62e7c20220041a4470c3","user":{"login":"rhyshort","id":1616727,"avatar_url":"https://avatars.githubusercontent.com/u/1616727?v=3","gravatar_id":"","url":"https://api.github.com/users/rhyshort","html_url":"https://github.com/rhyshort","followers_url":"https://api.github.com/users/rhyshort/followers","following_url":"https://api.github.com/users/rhyshort/following{/other_user}","gists_url":"https://api.github.com/users/rhyshort/gists{/gist_id}","starred_url":"https://api.github.com/users/rhyshort/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhyshort/subscriptions","organizations_url":"https://api.github.com/users/rhyshort/orgs","repos_url":"https://api.github.com/users/rhyshort/repos","events_url":"https://api.github.com/users/rhyshort/events{/privacy}","received_events_url":"https://api.github.com/users/rhyshort/received_events","type":"User","site_admin":false},"body":"we shouldn't capture `self` here, we should set a good example, and use:\r\n\r\n```objc\r\n__weak CDTViewController *weakSelf = self;\r\n[self.todoReplicator syncInBackgroundWithCompletionHandler:^{\r\n    __strong CDTViewController *self = weakSelf;\r\n    self toggleCompletedShown:nil];\r\n}];\r\n```\r\n\r\nor similar.\r\n","created_at":"2016-02-10T09:47:25Z","updated_at":"2016-02-10T09:47:25Z","html_url":"https://github.com/cloudant/CDTDatastore/pull/220#discussion_r52435122","pull_request_url":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/220","_links":{"self":{"href":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/comments/52435122"},"html":{"href":"https://github.com/cloudant/CDTDatastore/pull/220#discussion_r52435122"},"pull_request":{"href":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/220"}}},"pull_request":{"url":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/220","id":58127229,"html_url":"https://github.com/cloudant/CDTDatastore/pull/220","diff_url":"https://github.com/cloudant/CDTDatastore/pull/220.diff","patch_url":"https://github.com/cloudant/CDTDatastore/pull/220.patch","issue_url":"https://api.github.com/repos/cloudant/CDTDatastore/issues/220","number":220,"state":"open","locked":false,"title":"Update sample project.","user":{"login":"brynh","id":12249863,"avatar_url":"https://avatars.githubusercontent.com/u/12249863?v=3","gravatar_id":"","url":"https://api.github.com/users/brynh","html_url":"https://github.com/brynh","followers_url":"https://api.github.com/users/brynh/followers","following_url":"https://api.github.com/users/brynh/following{/other_user}","gists_url":"https://api.github.com/users/brynh/gists{/gist_id}","starred_url":"https://api.github.com/users/brynh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brynh/subscriptions","organizations_url":"https://api.github.com/users/brynh/orgs","repos_url":"https://api.github.com/users/brynh/repos","events_url":"https://api.github.com/users/brynh/events{/privacy}","received_events_url":"https://api.github.com/users/brynh/received_events","type":"User","site_admin":false},"body":"This is part 3 of a 3 part change to implement replication policies. Each of the 3 parts of the implementation of replication policies is in a separate branch.\r\n\r\n_The following text is common to all 3 PRs._\r\n\r\nThe 3 branches include:\r\n1. _replication-policies-1_: The main code changes implementing replication policies on iOS.\r\n2. _replication-policies-2-doc_: Documentation updates.\r\n3. _replication-policies-3-sample-project_: Updates to the sample project to add periodic replication when on WiFi.\r\n\r\n_What?_\r\nAdd mechanism to enable users to more easily specify the circumstances under which they want replication to occur. This allows relatively simple definition of policies within the constraints of [iOS background execution](https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html) - e.g.:\r\n* Do a pull replication every 2 hours;\r\n* Do a full sync every hour, but only when we have a Wifi connection;\r\n\r\n_Why?_\r\nPrior to this PR, it was more complicated to implement such policies and replication when the app was suspended was not supported. This aims to update the code to allow it to support the relatively simple configuration of policies by the user.\r\n\r\n_How?_\r\nWe need the replication policy management to work within the strict constraints of iOS and to allow background transfers while the app is suspended. This requires that data transfers between the device and server are performed using background sessions.\r\n\r\nThe code has therefore been modified to configure the `NSURLSession` using a background session configuration. Background session configurations must use delegates to process responses rather than completion handlers and corresponding changes have therefore been made in the code, making `CDTURLSession` the delegate handling the responses.\r\n\r\n`CDTURLSession` stores a mapping of the unique identifiers of `NSURLSessionTask` objects to their corresponding `CDTURLSessionTask` objects so that processing of the responses can be further delegated to the `CDTURLSessionTask` that sent the corresponding request.\r\n\r\nThe new `NSURLSessionConfigurationDelegate` allows a delegate to be set that enables the user to configure aspects of the `NSURLSessionConfiguration` - e.g. setting the `allowsCellularAccess` property to enable/disable use of the cellular data connection.\r\n\r\nSee the [Replication Policies User Guide](https://github.com/cloudant/CDTDatastore/blob/replication-policies-2-doc/doc/replication-policies.md) for further information on how replication policies are implemented.\r\n\r\nreviewer @rhyshort\r\nreviewer @tomblench","created_at":"2016-02-03T11:58:22Z","updated_at":"2016-02-10T09:47:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"de24d9da4c80440afef8b8b15397bcc136be8f80","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/220/commits","review_comments_url":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/220/comments","review_comment_url":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cloudant/CDTDatastore/issues/220/comments","statuses_url":"https://api.github.com/repos/cloudant/CDTDatastore/statuses/18a8b2d5e569b407158f62e7c20220041a4470c3","head":{"label":"cloudant:replication-policies-3-sample-project","ref":"replication-policies-3-sample-project","sha":"18a8b2d5e569b407158f62e7c20220041a4470c3","user":{"login":"cloudant","id":44642,"avatar_url":"https://avatars.githubusercontent.com/u/44642?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudant","html_url":"https://github.com/cloudant","followers_url":"https://api.github.com/users/cloudant/followers","following_url":"https://api.github.com/users/cloudant/following{/other_user}","gists_url":"https://api.github.com/users/cloudant/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudant/subscriptions","organizations_url":"https://api.github.com/users/cloudant/orgs","repos_url":"https://api.github.com/users/cloudant/repos","events_url":"https://api.github.com/users/cloudant/events{/privacy}","received_events_url":"https://api.github.com/users/cloudant/received_events","type":"Organization","site_admin":false},"repo":{"id":15022868,"name":"CDTDatastore","full_name":"cloudant/CDTDatastore","owner":{"login":"cloudant","id":44642,"avatar_url":"https://avatars.githubusercontent.com/u/44642?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudant","html_url":"https://github.com/cloudant","followers_url":"https://api.github.com/users/cloudant/followers","following_url":"https://api.github.com/users/cloudant/following{/other_user}","gists_url":"https://api.github.com/users/cloudant/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudant/subscriptions","organizations_url":"https://api.github.com/users/cloudant/orgs","repos_url":"https://api.github.com/users/cloudant/repos","events_url":"https://api.github.com/users/cloudant/events{/privacy}","received_events_url":"https://api.github.com/users/cloudant/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloudant/CDTDatastore","description":"Cloudant Sync iOS datastore library.","fork":false,"url":"https://api.github.com/repos/cloudant/CDTDatastore","forks_url":"https://api.github.com/repos/cloudant/CDTDatastore/forks","keys_url":"https://api.github.com/repos/cloudant/CDTDatastore/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloudant/CDTDatastore/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloudant/CDTDatastore/teams","hooks_url":"https://api.github.com/repos/cloudant/CDTDatastore/hooks","issue_events_url":"https://api.github.com/repos/cloudant/CDTDatastore/issues/events{/number}","events_url":"https://api.github.com/repos/cloudant/CDTDatastore/events","assignees_url":"https://api.github.com/repos/cloudant/CDTDatastore/assignees{/user}","branches_url":"https://api.github.com/repos/cloudant/CDTDatastore/branches{/branch}","tags_url":"https://api.github.com/repos/cloudant/CDTDatastore/tags","blobs_url":"https://api.github.com/repos/cloudant/CDTDatastore/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloudant/CDTDatastore/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloudant/CDTDatastore/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloudant/CDTDatastore/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloudant/CDTDatastore/statuses/{sha}","languages_url":"https://api.github.com/repos/cloudant/CDTDatastore/languages","stargazers_url":"https://api.github.com/repos/cloudant/CDTDatastore/stargazers","contributors_url":"https://api.github.com/repos/cloudant/CDTDatastore/contributors","subscribers_url":"https://api.github.com/repos/cloudant/CDTDatastore/subscribers","subscription_url":"https://api.github.com/repos/cloudant/CDTDatastore/subscription","commits_url":"https://api.github.com/repos/cloudant/CDTDatastore/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloudant/CDTDatastore/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloudant/CDTDatastore/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloudant/CDTDatastore/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloudant/CDTDatastore/contents/{+path}","compare_url":"https://api.github.com/repos/cloudant/CDTDatastore/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloudant/CDTDatastore/merges","archive_url":"https://api.github.com/repos/cloudant/CDTDatastore/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloudant/CDTDatastore/downloads","issues_url":"https://api.github.com/repos/cloudant/CDTDatastore/issues{/number}","pulls_url":"https://api.github.com/repos/cloudant/CDTDatastore/pulls{/number}","milestones_url":"https://api.github.com/repos/cloudant/CDTDatastore/milestones{/number}","notifications_url":"https://api.github.com/repos/cloudant/CDTDatastore/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloudant/CDTDatastore/labels{/name}","releases_url":"https://api.github.com/repos/cloudant/CDTDatastore/releases{/id}","deployments_url":"https://api.github.com/repos/cloudant/CDTDatastore/deployments","created_at":"2013-12-08T11:59:05Z","updated_at":"2016-02-02T17:42:13Z","pushed_at":"2016-02-08T19:33:31Z","git_url":"git://github.com/cloudant/CDTDatastore.git","ssh_url":"git@github.com:cloudant/CDTDatastore.git","clone_url":"https://github.com/cloudant/CDTDatastore.git","svn_url":"https://github.com/cloudant/CDTDatastore","homepage":null,"size":6695,"stargazers_count":95,"watchers_count":95,"language":"Objective-C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":23,"mirror_url":null,"open_issues_count":9,"forks":23,"open_issues":9,"watchers":95,"default_branch":"master"}},"base":{"label":"cloudant:replication-policies-2-doc","ref":"replication-policies-2-doc","sha":"84bf89703fbcdb9db583075df432a874e782fd8e","user":{"login":"cloudant","id":44642,"avatar_url":"https://avatars.githubusercontent.com/u/44642?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudant","html_url":"https://github.com/cloudant","followers_url":"https://api.github.com/users/cloudant/followers","following_url":"https://api.github.com/users/cloudant/following{/other_user}","gists_url":"https://api.github.com/users/cloudant/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudant/subscriptions","organizations_url":"https://api.github.com/users/cloudant/orgs","repos_url":"https://api.github.com/users/cloudant/repos","events_url":"https://api.github.com/users/cloudant/events{/privacy}","received_events_url":"https://api.github.com/users/cloudant/received_events","type":"Organization","site_admin":false},"repo":{"id":15022868,"name":"CDTDatastore","full_name":"cloudant/CDTDatastore","owner":{"login":"cloudant","id":44642,"avatar_url":"https://avatars.githubusercontent.com/u/44642?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudant","html_url":"https://github.com/cloudant","followers_url":"https://api.github.com/users/cloudant/followers","following_url":"https://api.github.com/users/cloudant/following{/other_user}","gists_url":"https://api.github.com/users/cloudant/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudant/subscriptions","organizations_url":"https://api.github.com/users/cloudant/orgs","repos_url":"https://api.github.com/users/cloudant/repos","events_url":"https://api.github.com/users/cloudant/events{/privacy}","received_events_url":"https://api.github.com/users/cloudant/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloudant/CDTDatastore","description":"Cloudant Sync iOS datastore library.","fork":false,"url":"https://api.github.com/repos/cloudant/CDTDatastore","forks_url":"https://api.github.com/repos/cloudant/CDTDatastore/forks","keys_url":"https://api.github.com/repos/cloudant/CDTDatastore/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloudant/CDTDatastore/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloudant/CDTDatastore/teams","hooks_url":"https://api.github.com/repos/cloudant/CDTDatastore/hooks","issue_events_url":"https://api.github.com/repos/cloudant/CDTDatastore/issues/events{/number}","events_url":"https://api.github.com/repos/cloudant/CDTDatastore/events","assignees_url":"https://api.github.com/repos/cloudant/CDTDatastore/assignees{/user}","branches_url":"https://api.github.com/repos/cloudant/CDTDatastore/branches{/branch}","tags_url":"https://api.github.com/repos/cloudant/CDTDatastore/tags","blobs_url":"https://api.github.com/repos/cloudant/CDTDatastore/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloudant/CDTDatastore/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloudant/CDTDatastore/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloudant/CDTDatastore/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloudant/CDTDatastore/statuses/{sha}","languages_url":"https://api.github.com/repos/cloudant/CDTDatastore/languages","stargazers_url":"https://api.github.com/repos/cloudant/CDTDatastore/stargazers","contributors_url":"https://api.github.com/repos/cloudant/CDTDatastore/contributors","subscribers_url":"https://api.github.com/repos/cloudant/CDTDatastore/subscribers","subscription_url":"https://api.github.com/repos/cloudant/CDTDatastore/subscription","commits_url":"https://api.github.com/repos/cloudant/CDTDatastore/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloudant/CDTDatastore/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloudant/CDTDatastore/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloudant/CDTDatastore/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloudant/CDTDatastore/contents/{+path}","compare_url":"https://api.github.com/repos/cloudant/CDTDatastore/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloudant/CDTDatastore/merges","archive_url":"https://api.github.com/repos/cloudant/CDTDatastore/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloudant/CDTDatastore/downloads","issues_url":"https://api.github.com/repos/cloudant/CDTDatastore/issues{/number}","pulls_url":"https://api.github.com/repos/cloudant/CDTDatastore/pulls{/number}","milestones_url":"https://api.github.com/repos/cloudant/CDTDatastore/milestones{/number}","notifications_url":"https://api.github.com/repos/cloudant/CDTDatastore/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloudant/CDTDatastore/labels{/name}","releases_url":"https://api.github.com/repos/cloudant/CDTDatastore/releases{/id}","deployments_url":"https://api.github.com/repos/cloudant/CDTDatastore/deployments","created_at":"2013-12-08T11:59:05Z","updated_at":"2016-02-02T17:42:13Z","pushed_at":"2016-02-08T19:33:31Z","git_url":"git://github.com/cloudant/CDTDatastore.git","ssh_url":"git@github.com:cloudant/CDTDatastore.git","clone_url":"https://github.com/cloudant/CDTDatastore.git","svn_url":"https://github.com/cloudant/CDTDatastore","homepage":null,"size":6695,"stargazers_count":95,"watchers_count":95,"language":"Objective-C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":23,"mirror_url":null,"open_issues_count":9,"forks":23,"open_issues":9,"watchers":95,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/220"},"html":{"href":"https://github.com/cloudant/CDTDatastore/pull/220"},"issue":{"href":"https://api.github.com/repos/cloudant/CDTDatastore/issues/220"},"comments":{"href":"https://api.github.com/repos/cloudant/CDTDatastore/issues/220/comments"},"review_comments":{"href":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/220/comments"},"review_comment":{"href":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/220/commits"},"statuses":{"href":"https://api.github.com/repos/cloudant/CDTDatastore/statuses/18a8b2d5e569b407158f62e7c20220041a4470c3"}}}}