Monday, January 19, 2015

Getting Calendar Event with Cycript

Testing in Cycript

This is how I would go about finding the Calendar Event in Cycript.
First I would look at Apple's documentation on the calendar. LINK <- this can usually be found by searching their documents or using Google.

Not far down this page you will see listing 1-1.
NSCalendar *calendar = [NSCalendar currentCalendar];

Easy enough here is how we can get the calendar object, it even shows us how to retrieve events. Lets work on altering this to run in Cycript. First log into cycript via terminal. To do this type in ssh root@yourip it will ask for your password enter it. Default password is alpine. Then type cycript -p SpringBoard


You are now logged into Cycript you can tell by the cy#

We start adding what the Apple dev center says. As you see below I followed most of what the Apple site shown, only removing things which look like NSCalendar *-  as we only need a variable.


Lets go line by line.

calendar = [NSCalendar currentCalendar];
Gets the calendar wrapper

oneDayAgoComponents = [[NSDateComponents alloc] init];
Gets the current date

oneDayAgoComponents.day = -1; 
Sets the day -1 from today

oneDayAgo = [calendar dateByAddingComponents:oneDayAgoComponents toDate:[NSDate date]options:0];
Takes the calendar wrapper and gets a date from the oneDayAgoComponents which will return a complete date for today.

!.. Apple uses oneYearFromNowComponents we don't need one year from now instead we need a day or two from now.

nextDayFromNowComponents = [[[NSDateComponents alloc] init]autorelease];
Allocate (create) a new date component

nextDayFromNowComponents.day = 1;
set it to a day after current

nextDayFromNow = [calendar dateByAddingComponents: nextDayFromNowComponents toDate: [NSDate date]options: 0];
get complete date.

store = [[[EKEventStore alloc] init]autorelease];
Allocate (create) a new EKEventStore

predicate = [store predicateForEventsWithStartDate: oneDayAgo endDate: nextDayFromNow calendars: nil];
Take the store and add our dates. It will return the days we want to get. (EKEventPredicate start:1/18/15, 7:27 PM; end:1/20/15, 7:29 PM; cals:(null))

events = [store eventsMatchingPredicate: predicate];
Call the store and get the matches for our dates. This will return all events for these days. As you see above, which I will post again here. It gives us events.


The events returned is an object. So we can pull info just as you would any object.

events[0] would return the first event
events[1] would return the second and so on.

Once we get each event say event[0] (first event) we can get certain values such as title, location, and any other info in the object.



events[0].title
shows current event title which is what we are going to put in our cydget.


Creating the Cydget

I will start by thinking you have the basic concept how to create the cydget and jump straight into the html code.



Here we do basically the same thing we did in Cycript itself. More than likely if it works in Cycript it will work the same way in Cydget.

At the end of the getcalendarEvents I put an if statement if(events) this means if there is an event it will return events[0].title. There needs to be and could be more optimization here. For example and else{} statement could be added incase there is no event.


Here is a more advanced process that will give you all events instead of one.














No comments:

Post a Comment