【问题标题】:EKEventStore request access not workingEKEventStore 请求访问不起作用
【发布时间】:2015-11-24 19:24:38
【问题描述】:

var eventStore: EKEventStore?

@IBAction func bbbbbbb(sender: UIButton) {
        if eventStore == nil {
            eventStore = EKEventStore()
        }
        self.eventStore?.requestAccessToEntityType(EKEntityType.Event, completion: { (aBool, error) -> Void in
            print(error, aBool)
        })
}

打印为零,始终为假...其行为就像用户已经拒绝访问,但从未显示提示。相同的代码当然适用于相同设备上的新空白应用程序。我尝试过的事情:在设备、模拟器上休息设置并使用从未安装过该应用程序的新设备,当然还有清理项目,但没有成功。另外,在应用程序设置中,日历权限也没有显示。有什么想法吗?

【问题讨论】:

    标签: ios swift calendar ekeventstore


    【解决方案1】:

    使用iOS 10,您需要在plist 中添加以下密钥,以允许应用访问日历(如果没有,应用在请求访问时会简单地崩溃):

    key: "Privacy - Calendars Usage Description"
    value: "$(PRODUCT_NAME) calendar events"
    

    看这里:

    https://iosdevcenters.blogspot.com/2016/09/infoplist-privacy-settings-in-ios-10.html

    【讨论】:

    • 谢谢,我原以为就是这样。
    【解决方案2】:

    试试下面的代码

        let eventStore = EKEventStore()
        eventStore.requestAccessToEntityType(EKEntityType.Event) { (granted: Bool, error: NSError?) -> Void in
    
            if granted{
                print("Got access")
                let defaultCalendar = eventStore.defaultCalendarForNewEvents
                print("\(defaultCalendar.calendarIdentifier)")
            }else{
                print("The app is not permitted to access reminders, make sure to grant permission in the settings and try again")
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-23
      • 1970-01-01
      • 1970-01-01
      • 2017-12-30
      • 1970-01-01
      • 2019-11-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多