Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open calendar with event - NSURL calshow:

I'm wondering if there is someone who knows how to launch calendar with a specific event from APP

I've done some research and I've come up with two ways to open native calendar from inside the app using NSURL

  1. "calshow://" which opens calendar at current date
  2. "calshow:\(someNSDate.timeIntervalSinceReferenceDate)" which opens calendar with date of someNSDate

I also found this website that lists calshow:x?eventid=id as url but I'm not sure if this works (listed as not public) and I couldn't get it working myself, tried using :

event.calendarItemExternalIdentifier
event.eventIdentifier
event.calendarItemIdentifier

currently I'm using this code to open the calendar app at the finalInterval date, date of the event

        if let day = hackathon?.start {

            let today = NSDate()
            let timeSince = NSDate.timeIntervalSinceReferenceDate() // this plus
            let todayToFutureDate = day.timeIntervalSinceDate(today)
            let finalInterval = todayToFutureDate + timeSince

            UIApplication.sharedApplication().openURL(NSURL(string: "calshow:\(finalInterval)")!)
        }

What I'd like to do is to open up the calendar with an event id or something like that that would show the event

if you have any questions for more info just ask, I'll be around

like image 938
Fero Avatar asked Aug 08 '15 18:08

Fero


1 Answers

Try with this, create this function

func gotoAppleCalendar(date: NSDate) {
  let interval = date.timeIntervalSinceReferenceDate
  let url = NSURL(string: "calshow:\(interval)")!
  UIApplication.sharedApplication().openURL(url)
}

Call the function using the event start date as parameter

 gotoAppleCalendar(event.startDate)

This open the apple calendar showing the added event

like image 100
Deyson Avatar answered Oct 17 '22 00:10

Deyson