{"id":118,"date":"2013-02-21T00:59:14","date_gmt":"2013-02-20T15:59:14","guid":{"rendered":"http:\/\/adreamer.godohosting.com\/en\/?p=118"},"modified":"2013-02-26T23:23:05","modified_gmt":"2013-02-26T14:23:05","slug":"how-to-add-geofencing-reminders-to-ios-programically","status":"publish","type":"post","link":"http:\/\/milkdrops.net\/en\/archives\/118","title":{"rendered":"How to add geofencing Reminders to iOS programically"},"content":{"rendered":"<p>Reference : <a href=\"http:\/\/developer.apple.com\/library\/ios\/documentation\/DataManagement\/Conceptual\/EventKitProgGuide\/ReadingAndWritingReminders\/ReadingAndWritingReminders.html#\/\/apple_ref\/doc\/uid\/TP40009765-CH5-SW1\">Calendar and Reminders Programming Guide<\/a> from iOS Developer Library<\/p>\n<p>Apple provides a way to add a Reminder through EventKit from iOS 6.<\/p>\n<p>1. Before start coding, you should add the EventKit Framework to the target first.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/adreamer.godohosting.com\/en\/wp-content\/uploads\/2013\/02\/eventkit.jpg\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-125\" alt=\"eventkit\" src=\"https:\/\/i0.wp.com\/adreamer.godohosting.com\/en\/wp-content\/uploads\/2013\/02\/eventkit-300x270.jpg?resize=240%2C216\" width=\"240\" height=\"216\" srcset=\"https:\/\/i0.wp.com\/milkdrops.net\/en\/wp-content\/uploads\/2013\/02\/eventkit.jpg?resize=300%2C270 300w, https:\/\/i0.wp.com\/milkdrops.net\/en\/wp-content\/uploads\/2013\/02\/eventkit.jpg?w=430 430w\" sizes=\"auto, (max-width: 240px) 100vw, 240px\" \/><\/a><\/p>\n<p>2. Check whether iOS is over 6. (Reminder API is available above iOS6)<\/p>\n<p>&nbsp;<\/p>\n<pre lang=\"objc\" line=\"1\">\/\/ Check API (above iOS6)\r\nif ([[EKEventStore class] instancesRespondToSelector:@selector(requestAccessToEntityType:completion:)] == NO) {\r\n    return nil;\r\n}<\/pre>\n<p>3. Init EKEventStore and request access.<\/p>\n<pre lang=\"objc\" line=\"5\">EKEventStore *store = [[EKEventStore alloc] init];\r\n\r\n[store requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error) {\r\n    \/\/ handle access here\r\n    if (granted) {\r\n        \/\/ Create Reminder... [1]\r\n    }\r\n    [store release];\r\n}];<\/pre>\n<p>4. If access is granted, Create reminder and add location alarm. (Code should be inside [1])<\/p>\n<pre lang=\"objc\" line=\"15\">EKReminder *reminder = [EKReminder reminderWithEventStore:store];\r\nreminder.title = @\"Geofence Reminder\";\r\nreminder.calendar = [store defaultCalendarForNewReminders]; \/\/ Use default calendar for new reminders\r\n\r\nEKAlarm *alarm = [[EKAlarm alloc] init];\r\n\r\nEKStructuredLocation *location = [EKStructuredLocation locationWithTitle:@\"Location title\"];\r\nCLLocation *clLocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];\r\nlocation.geoLocation = clLocation;\r\n[clLocation release];\r\n\r\n[alarm setStructuredLocation:location];\r\nalarm.proximity = EKAlarmProximityEnter; \/\/ Remind when enter or leave\r\n[reminder addAlarm:alarm];\r\n[alarm release];\r\n\r\n\/\/ Save reminder\r\nNSError *error;\r\n[store saveReminder:reminder commit:YES error:&amp;error];\r\nif (error != nil) {\r\n    NSLog(@\"reminder error:%@\",[error description]);\r\n}<\/pre>\n<p>Done!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Reference : Calendar and Reminders Programming Guide from iOS Developer Library Apple provides a way to add a Reminder through EventKit from iOS 6. 1. Before start coding, you should add the EventKit Framework to the target first. 2. Check whether iOS is over 6. (Reminder API is available above iOS6) &nbsp; \/\/ Check API &hellip; <a href=\"http:\/\/milkdrops.net\/en\/archives\/118\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">How to add geofencing Reminders to iOS programically<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,21],"tags":[58,95,57],"class_list":["post-118","post","type-post","status-publish","format-standard","hentry","category-devel","category-ios","tag-geofence","tag-ios","tag-reminder"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/milkdrops.net\/en\/wp-json\/wp\/v2\/posts\/118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/milkdrops.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/milkdrops.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/milkdrops.net\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/milkdrops.net\/en\/wp-json\/wp\/v2\/comments?post=118"}],"version-history":[{"count":9,"href":"http:\/\/milkdrops.net\/en\/wp-json\/wp\/v2\/posts\/118\/revisions"}],"predecessor-version":[{"id":171,"href":"http:\/\/milkdrops.net\/en\/wp-json\/wp\/v2\/posts\/118\/revisions\/171"}],"wp:attachment":[{"href":"http:\/\/milkdrops.net\/en\/wp-json\/wp\/v2\/media?parent=118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/milkdrops.net\/en\/wp-json\/wp\/v2\/categories?post=118"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/milkdrops.net\/en\/wp-json\/wp\/v2\/tags?post=118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}