Created
May 14, 2019 01:50
-
-
Save tmtk75/9a7a5f65e1459297951a61220bb5fbd1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//import Cocoa | |
//var str = "Hello, playground" | |
import EventKit | |
let eventStore = EKEventStore() | |
func allowAuthorization() { | |
if getAuthorization_status() { | |
// 許可されている | |
return | |
} else { | |
// 許可されていない | |
eventStore.requestAccess(to:.event, completion: { | |
(granted, error) in | |
if granted { | |
return | |
} | |
else { | |
print("Not allowed") | |
} | |
}) | |
} | |
} | |
// 認証ステータスを確認する | |
func getAuthorization_status() -> Bool { | |
// 認証ステータスを取得 | |
let status = EKEventStore.authorizationStatus(for:.event) | |
// ステータスを表示 許可されている場合のみtrueを返す | |
switch status { | |
case .notDetermined: | |
print("NotDetermined") | |
return false | |
case .denied: | |
print("Denied") | |
return false | |
case .authorized: | |
print("Authorized") | |
return true | |
case .restricted: | |
print("Restricted") | |
return false | |
} | |
} | |
allowAuthorization() | |
// getAuthorization_status() | |
func viewDidLoad() { | |
// eventStore = EKEventStore() | |
eventStore.requestAccess(to: .reminder) { (granted, error) in | |
print("OK") | |
// let allReminders = EKReminder() | |
let cals = eventStore.calendars(for: .reminder) | |
let predicate = eventStore.predicateForIncompleteReminders(withDueDateStarting: nil, ending: nil, calendars: cals) | |
eventStore.fetchReminders(matching: predicate, completion: { (reminders: [EKReminder]?) -> Void in | |
print(reminders!) | |
var a: [[String:Any]] = [] | |
for reminder: EKReminder? in reminders! as [EKReminder?] ?? [EKReminder?]() { | |
a.append(["title": reminder?.title as Any]) | |
} | |
do { | |
let data = try JSONSerialization.data(withJSONObject: a) | |
let s = String(data: data, encoding: String.Encoding.utf8) | |
print(s!) | |
} catch let err { | |
print(err) | |
} | |
}) | |
} | |
} | |
viewDidLoad() | |
print(".") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works on Playground, but doesn't work with
swift
command in iTerm2.The latter returns empty.