Information not being received from server? - iphone

Okay, my problem is very simple. Below is my code that is receiving prices from an API, in my code I want the today current price to be displayed, yesterdays price, and the change in percent from yesterday to today. Unfortunately, only the current price is showing properly, but the yesterday and the percent change just show N/A.
Any help is appreciated!
if (refreshing) return;
refreshing = YES;
UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES;
//self.priceLabel.text = #"Loading...";
//self.yesterdayLabel.text = #"Loading...";
//self.changeLabel.text = #"Loading...";
[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"https://coinbase.com/api/v1/prices/spot_rate"]] queue:[NSOperationQueue mainQueue] completionHandler:^ (NSURLResponse *req, NSData *recv, NSError *err) {
if (err) {
// report
[self setCurrentPrice:#"N/A"];
refreshing = NO;
return;
}
NSError *newError = nil;
NSDictionary *serial = [NSJSONSerialization JSONObjectWithData:recv options:0 error:&newError];
if (newError) {
// report
[self setCurrentPrice:#"N/A"];
refreshing = NO;
return;
}
NSString *amount = [serial objectForKey:#"amount"];
NSString *price = [NSString stringWithFormat:#"%# %#", amount, [serial objectForKey:#"currency"]];
[self setCurrentPrice:[NSString stringWithFormat:#"%#", price]];
// maybe setup a better method.
float diff = [yesterdaysPrice floatValue];
if (diff == 0.0)
self.differenceInPrices = #"N/A";
else {
float amt = [amount floatValue];
float percentChange = amt/diff;
if ((diff == 0) || (amt == diff))
percentChange = 0.00;
percentChange *= 100.00;
self.differenceInPrices = [NSString stringWithFormat:#"%f%%", percentChange];
}
NSMutableDictionary *saveState = [[[NSUserDefaults standardUserDefaults] objectForKey:#"save"] mutableCopy];
[saveState setObject:price forKey:#"price"];
[saveState setObject:yesterdaysPrice forKey:#"lastCheckedPrice"];
NSDateComponents *compon = [[NSCalendar currentCalendar] components:(NSUndefinedDateComponent) fromDate:[NSDate date]];
[saveState setObject:[NSString stringWithFormat:#"%ld", (usingYesterdaysPrices ? [[saveState objectForKey:#"day"] intValue] : [compon day])] forKey:#"day"];
[[NSUserDefaults standardUserDefaults] setObject:saveState forKey:#"save"];
[[NSUserDefaults standardUserDefaults] synchronize];
self.priceLabel.text =self.currentPrice;
self.yesterdayLabel.text = [NSString stringWithFormat:#"%#", yesterdaysPrice];
self.changeLabel.text = differenceInPrices;
app.networkActivityIndicatorVisible = NO;
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:#"MM/dd/yyyy"];
NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
[timeFormat setDateFormat:#"h:mm:ss aa"];
NSDate *now = [[NSDate alloc] init];
NSString *theDate = [dateFormat stringFromDate:now];
NSString *theTime = [timeFormat stringFromDate:now];
lstUpdate.text = [NSString stringWithFormat:#"Updated: %# at %#", theDate, theTime];
refreshing = NO;
}];
I also have this code in my viewDidLoad,
[super viewDidLoad];
refreshing = NO;
NSDictionary *save = [[NSUserDefaults standardUserDefaults] objectForKey:#"save"];
if (save) {
int timeStamp = [[save objectForKey:#"day"] intValue];
NSDateComponents *compon = [[NSCalendar currentCalendar] components:(NSUndefinedDateComponent) fromDate:[NSDate date]];
if ([compon day] != timeStamp) {
usingYesterdaysPrices = YES;
yesterdaysPrice = [save objectForKey:#"lastCheckedPrice"];
if (!yesterdaysPrice) {
yesterdaysPrice = #"N/A";
}
}
}
else {
yesterdaysPrice = #"N/A";
}
self.differenceInPrices = #"N/A";
[self sendNewRequest:nil];
[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:#selector(sendNewRequest:) userInfo:Nil repeats:YES];

Related

How to compare curent time lie between two time slot

I hava an array of NSDictionary like this.
{
id = 12;
"time_from" = "12:00";
"time_to" = "16:00";
"timing_name" = Lunch;
},
{
id = 11;
"time_from" = "08:00";
"time_to" = "12:00";
"timing_name" = BreakFast;
},
{
id = 13;
"time_from" = "09:00";
"time_to" = "10:00";
"timing_name" = Dinner;
}
Suppose my current time is 8:45 then how can we find exact dictionary using predicate if current time exit between time_from and time_to.
Actully i need a predicate.
You can try this,
NSMutableArray *testArray = [NSMutableArray array];
NSMutableDictionary *testDict = [NSMutableDictionary dictionary];
[testDict setObject:#"12:45" forKey:#"time-from"];
[testDict setObject:#"14:45" forKey:#"time-to"];
[testArray addObject:testDict];
NSPredicate *timePredicate = [NSPredicate predicateWithBlock:^BOOL(NSMutableDictionary *dict, NSDictionary *bindings) {
NSString *timeFromString = [dict objectForKey:#"time-from"];
NSString *timeToString = [dict objectForKey:#"time-from"];
// find minutes from 00-0
//get current time minutes from 00-00
return (currentTimeMinutes>startimeMinutes) && (currentTimeMinutes<=endtimeMinutes)
}];
[testArray filterUsingPredicate:timePredicate];
-(void)makeCalculation
{
NSMutableDictionary *temp=[[NSMutableDictionary alloc]init];
[temp setObject:#"13" forKey:#"id"];
[temp setObject:#"12:00" forKey:#"timeFrom"];
[temp setObject:#"16:00" forKey:#"timeTo"];
NSMutableDictionary *temp1=[[NSMutableDictionary alloc]init];
[temp1 setObject:#"13" forKey:#"id"];
[temp1 setObject:#"08:00" forKey:#"timeFrom"];
[temp1 setObject:#"12:00" forKey:#"timeTo"];
NSMutableDictionary *temp2=[[NSMutableDictionary alloc]init];
[temp2 setObject:#"13" forKey:#"id"];
[temp2 setObject:#"09:00" forKey:#"timeFrom"];
[temp2 setObject:#"10:00" forKey:#"timeTo"];
NSMutableArray *arrayOfDict=[[NSMutableArray alloc]init];
[arrayOfDict addObject:temp];
[arrayOfDict addObject:temp1];
[arrayOfDict addObject:temp2];
NSMutableArray *timeToCompare=[[NSMutableArray alloc]initWithObjects:#"8:45",#"8:45", nil];
for(int k=0;k<[arrayOfDict count];k++)
{
NSMutableDictionary *temp=[arrayOfDict objectAtIndex:k];
NSString *timeFrom=[temp objectForKey:#"timeFrom"];
NSString *timeTo=[temp objectForKey:#"timeTo"];
NSMutableArray *tempTocheck=[[NSMutableArray alloc]initWithObjects:timeFrom,timeTo, nil];
if([self isTimeClash:timeToCompare compareWith:tempTocheck])
{
NSLog(#"Time Belong in id:%#",[temp objectForKey:#"id"]);
}
}
}
-(BOOL)isTimeClash:(NSMutableArray *)timeToCheck compareWith:(NSMutableArray *)timeToCompare
{
int Start1=[self getMinitesFromTime:[timeToCheck objectAtIndex:0]];
int end1=[self getMinitesFromTime:[timeToCheck objectAtIndex:1]];
int start2=[self getMinitesFromTime:[timeToCompare objectAtIndex:0]];
int end2=[self getMinitesFromTime:[timeToCompare objectAtIndex:1]];
if(start2>=end1 || end2<=Start1)
{
NSLog(#"Clash not happeed");
return NO;
}
else
{
NSLog(#"clash hapens ");
return YES;
}
}
-(int)getMinitesFromTime:(NSString *)timeINHours
{
NSInteger hrVal1 = [(timeINHours) intValue] ;
NSArray *array1 = [timeINHours componentsSeparatedByString:#":"];
int minVal1 = [[array1 lastObject]intValue];
hrVal1 = hrVal1 *60;
minVal1 = hrVal1 + minVal1;
return minVal1;
}
Try to use this one...
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:[NSDate date]];
NSInteger currHr = [components hour];
NSInteger currtMin = [components minute];
NSString *startTime = #"10:00";
NSString *endTime = #"16:00";
int stHr = [[[startTime componentsSeparatedByString:#":"] objectAtIndex:0] intValue];
int stMin = [[[startTime componentsSeparatedByString:#":"] objectAtIndex:1] intValue];
int enHr = [[[endTime componentsSeparatedByString:#":"] objectAtIndex:0] intValue];
int enMin = [[[endTime componentsSeparatedByString:#":"] objectAtIndex:1] intValue];
int formStTime = (stHr*60)+stMin;
int formEnTime = (enHr*60)+enMin;
int nowTime = (currHr*60)+currtMin;
if(nowTime >= formStTime && nowTime <= formEnTime)
{
// Do Some Stuff..
}
The array timings contains you array. You may want to include the time in 24 hour format for uniformity.
NSDateFormatter *dateFormatter = [NSDateFormatter new];
[dateFormatter setDateFormat:#"HH:mm"];
NSDate *now = [NSDate date];
__block NSString *status = nil;
[timings enumerateObjectsUsingBlock:^(NSDictionary * dict, NSUInteger idx, BOOL *stop)
{
NSDate *date1 = [dateFormatter dateFromString:dict[#"time_from"]];
NSDate *date2 = [dateFormatter dateFromString:dict[#"time_to"]];
NSDateComponents *date1Components = [[NSCalendar currentCalendar]components:NSHourCalendarUnit|NSMinuteCalendarUnit
fromDate:date1];
NSDateComponents *date2Components = [[NSCalendar currentCalendar]components:NSHourCalendarUnit|NSMinuteCalendarUnit
fromDate:date2];
NSDateComponents *nowDateComponents = [[NSCalendar currentCalendar]components:NSHourCalendarUnit|NSMinuteCalendarUnit
fromDate:now];
NSInteger fromMinutes = date1Components.hour*60+date1Components.minute;
NSInteger toMinutes = date2Components.hour*60+date2Components.minute;
NSInteger nowMinutes = nowDateComponents.hour*60+nowDateComponents.minute;
if (nowMinutes>fromMinutes && nowMinutes<toMinutes) {
status = dict[#"timing_name"];
}
}];
NSLog(#"%#",status);

Add calendar on iCloud on iOS

i'm trying to add a calendar to the iCloud EKSource, i'm trying to find the iCloud calendar in this way:
EKSource *theSource = nil;
for (EKSource *source in eventStore.sources) {
if (source.sourceType == EKSourceTypeCalDAV && [source.title isEqualToString:#"iCloud"]) {
theSource = source;
break;
}
}
but don't find my any EKSource, how i can add a calendar on icloud and see how many calendar are in icloud?
Perhaps something like this will help you..
- (void)saveEventToiCloud {
EKEventStore *eventDB = [[EKEventStore alloc] init];
NSArray *calender = [[eventDB calendars] retain];
NSString * typeString = #"";
EKCalendar *iCloud;
for (EKCalendar *thisCalendar in calenders)
{
EKCalendarType type = thisCalendar.type;
if (type == EKCalendarTypeCalDAV)
{
NSString *calName=[NSString stringWithFormat:#"%#", thisCalendar.title];
NSRange range = [calName rangeOfString:#"iCloud"]; //Couldn't find better way, if there is, then tell me too. :)
if(range.length!=0)
{
//icloud
iCloud = thisCalendar;
break;
}
else
{
//any other email account
}
}
}
if(iCloud){
NSError *error = nil;
EKEvent *thisEvent = [[EKEvent eventWithEventStore:eventDB] retain];
thisEvent.title = #"Title";
thisEvent.startDate = [NSDate date];
thisEvent.endDate = [NSDate date];
thisEvent.calendar = iCloud ;
BOOL saved = [eventDB saveEvent:thisEvent span:EKSpanThisEvent error:&error];
NSLog(#"Saved calendar event = %#\n", (saved ? #"YES" : #"NO"));
[thisEvent release];
thisEvent=nil;
}
[events release];
[eventDB release];
}

Why application shows low memory warning during heap shot analysis?

I am developing one application in which recurring transactions are inserted in database.while i am doing heap shot analysis it shows low memory warning while inserting data.its inserting 1200 records approximately.The code for insertion is as below.
-(void)generateReccuringEntry:(int)tranId withAllDate:(BOOL)isAll
{
NSMutableArray *arrDates = [[NSMutableArray alloc] init] ;
NSArray *arr = [[_dicSaveData valueForKey:#"tran_repeatd"] componentsSeparatedByString:#" "];
int day;
if ([self getDayWithDayMonth:[arr objectAtIndex:1]] == 0) {
day = [self getDay:[arr objectAtIndex:1]];
}
else{
day = 1;
}
NSDate *startDate = [_dicSaveData valueForKey:#"tran_date"];
NSString *strEndDate = [NSString stringWithFormat:#"%#",[_dicSaveData valueForKey:#"tran_enddate"]];
NSDate *endDate = nil;
strEndDate = [strEndDate stringByReplacingOccurrencesOfString:#"(null)" withString:#""];
if (![strEndDate stringIsEmpty]) {
endDate = [_dicSaveData valueForKey:#"tran_enddate"];
}
else {
//if end date not selected
endDate = [[startDate dateByAddingYear:1]lastOfYearDate];
}
//get start recurring day
NSString *strDay = [[arr lastObject] stringByReplacingOccurrencesOfString:#"()" withString:#""];
//check start recuring day selected or not
if ([strDay hasPrefix:#"("] && [strDay hasSuffix:#")"])
{
startDate = [self getStartDay:[arr lastObject] withStartingDate:startDate];
if ([startDate compare:endDate]==NSOrderedDescending || [startDate compare:endDate]==NSOrderedSame)
{
SafeRelease(arrDates);
return;
}
if (isAll)
{
NSError *error = nil;
NSString *strQuery = [NSString stringWithFormat:#"insert into recuring values (NULL,%i,%#,%#,'%#',%#,'%#','','%#','%#',%i,1,'%#',0)",tranId,[_dicSaveData valueForKey:#"cat_id"],[_dicSaveData valueForKey:#"subcat_id"],_txtDesc.text,_txtAmount.text,sDate,[_dicSaveData valueForKey:#"tran_repeatd"],eDate,_flagForever,[_dicSaveData valueForKey:#"categoryText"]];
strQuery = [strQuery stringByReplacingOccurrencesOfString:#"(null)" withString:#""];
[NSNumber requestWithSynchronousExcuteQuery:strQuery withReturnningError:&error];
if (error) {
[AppDelegate showAlert:[error description] withTitle:#"Error!"];
}
}
else{
NSDate *currentDate = [[NSDate date] getDateWithDeviceTimeZone];
if ([startDate compare:currentDate]== NSOrderedDescending)
{
NSError *error = nil;
NSString *strQuery = [NSString stringWithFormat:#"insert into recuring values (NULL,%i,%#,%#,'%#',%#,'%#','','%#','%#',%i,1,'%#',0)",tranId,[_dicSaveData valueForKey:#"cat_id"],[_dicSaveData valueForKey:#"subcat_id"],_txtDesc.text,_txtAmount.text,sDate,[_dicSaveData valueForKey:#"tran_repeatd"],eDate,_flagForever,[_dicSaveData valueForKey:#"categoryText"]];
strQuery = [strQuery stringByReplacingOccurrencesOfString:#"(null)" withString:#""];
[NSNumber requestWithSynchronousExcuteQuery:strQuery withReturnningError:&error];
if (error) {
[AppDelegate showAlert:[error description] withTitle:#"Error!"];
}
}
}
}
int index = 2;
if (day == 1) {
index = 1;
}
do {
if ([[arr objectAtIndex:index] isEqualToString:#"Week"])
{
startDate = [startDate dateByAddingWeek:day];
}
else if([[arr objectAtIndex:index] isEqualToString:#"Month"])
{
startDate = [startDate dateByAddingMonth:day];
}
else
{
startDate = [startDate dateByAddingDays:day];
}
if (isAll)
{
NSError *error = nil;
NSString *strQuery = [NSString stringWithFormat:#"insert into recuring values (NULL,%i,%#,%#,'%#',%#,'%#','','%#','%#',%i,1,'%#',0)",tranId,[_dicSaveData valueForKey:#"cat_id"],[_dicSaveData valueForKey:#"subcat_id"],_txtDesc.text,_txtAmount.text,sDate,[_dicSaveData valueForKey:#"tran_repeatd"],eDate,_flagForever,[_dicSaveData valueForKey:#"categoryText"]];
strQuery = [strQuery stringByReplacingOccurrencesOfString:#"(null)" withString:#""];
[NSNumber requestWithSynchronousExcuteQuery:strQuery withReturnningError:&error];
if (error) {
[AppDelegate showAlert:[error description] withTitle:#"Error!"];
}
}
//add recuring for only for future dates
else
{
NSDate *currentDate = [[NSDate date] getDateWithDeviceTimeZone];
if ([startDate compare:currentDate]== NSOrderedDescending)
{
NSError *error = nil;
NSString *strQuery = [NSString stringWithFormat:#"insert into recuring values (NULL,%i,%#,%#,'%#',%#,'%#','','%#','%#',%i,1,'%#',0)",tranId,[_dicSaveData valueForKey:#"cat_id"],[_dicSaveData valueForKey:#"subcat_id"],_txtDesc.text,_txtAmount.text,sDate,[_dicSaveData valueForKey:#"tran_repeatd"],eDate,_flagForever,[_dicSaveData valueForKey:#"categoryText"]];
strQuery = [strQuery stringByReplacingOccurrencesOfString:#"(null)" withString:#""];
[NSNumber requestWithSynchronousExcuteQuery:strQuery withReturnningError:&error];
if (error) {
[AppDelegate showAlert:[error description] withTitle:#"Error!"];
}
}
}
} while ([startDate compare:endDate]==NSOrderedAscending );
SafeRelease(arrDates);
}
can anyone tell that what is the problem with this code.so that its consuming so much memory?
Update:I have converted app to ARC.but it still shows memory warning.
Highly recommend you convert (if you can) to ARC. The compiler is far more capable of inserting the most efficient retains/releases for you. Would also completely remove any need for anything like SafeRelease.

Calendar API changing

http://code.google.com/p/scm-subversion/source/browse/trunk/iPhone/CalendarTest/?r=4#CalendarTest%253Fstate%253Dclosed
I am using the above mentioned Calendar API. In CalendarTestViewController.m class we are getting the date. Now I have declared a global variable nsstring type and I want to use that date into another new class by using global variable. I have tried this a number of times but unable to get the output. If anyone know how can I use the selected date by using Calendar API, then please give me some solution.
Thanks in advance.
CODE
- (void)calendarView:(KLCalendarView *)calendarView tappedTile:(KLTile *)aTile{
NSLog(#"Date Selected is %#",[aTile date]);
str=(NSString *)[aTile date];
}
NSLog(#"str:%#",str);
glbdate1 = (NSString *)[aTile date];
NSLog(#"glbdate1:%#",glbdate1);
}
//I have declared the glbdate1 variable globally in app delegate file and i have made the new class calenderview
//I want to display the date in textfield by using global variable. Here is code in calenderview
-(void)viewWillAppear:(BOOL)animated {
if ([glbdate1 length] != 0)
{
from.text = glbdate1;
}
}
You have to convert the NSDate to NSString as follows,
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"yyyy-mm-dd HH:mm:ss"];
NSString *dateString=[dateFormatter stringFromDate:date];
Then the same NSString value can be converted to NSDate as,
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"yyyy-mm-dd HH:mm:ss"];
NSDate *dateFromString=[dateFormatter dateFromString:dateString];
-(BOOL)isDateinEventArray:(NSString*)iDateString{
//NSString *searchText = lblDate.text;
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
for (ToDo *todoObj in appDelegate.todoArray)
{
NSString *date = todoObj.startDate;
[searchArray addObject:date];
}
if ([searchArray count] > 0) {
for (NSString *sTemp in searchArray)
{
NSRange titleResultsRange = [sTemp rangeOfString:iDateString
options:NSCaseInsensitiveSearch];
if (titleResultsRange.length > 0)
[copyListOfItems addObject:sTemp];
}
[searchArray release];
searchArray = nil;
}
if ([copyListOfItems count] > 0) {
return TRUE;
}else{
return FALSE;
}
}
/*----- Calendar Delegates -----> */
- (void)calendarView:(KLCalendarView *)calendarView tappedTile:(KLTile *)aTile{
NSLog(#"Date Selected is %#",[aTile date]);
// NSString *stringFromDate =
// [[NSString alloc]initWithString:[NSString stringWithFormat:#"%02i-%02i-%i",[aTile.date dayOfMonth],
//
[aTile.date monthOfYear],[aTile.date yearOfCommonEra]]];
NSString *stringFromDate = [[NSString alloc]initWithString:[NSString stringWithFormat:#"%02i-%02i-%02i",[aTile.date yearOfCommonEra],
[aTile.date monthOfYear],[aTile.date dayOfMonth]]];
if([self isDateinEventArray:stringFromDate]){
selectedDate = [aTile date];
eventFoundMsg = #"Events are found on this date.";
eventMsgTag = 1;
}else{
eventFoundMsg = #"No events are found on this date.";
eventMsgTag = 0;
}
[stringFromDate release];
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"Event Message"
message:eventFoundMsg
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles:nil]autorelease];
alert.tag = eventMsgTag;
[alert show];
[aTile flash];
/*
if(tile == nil)
tile = aTile;
else
[tile restoreBackgroundColor];
*/
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (eventMsgTag == 1) {
if (buttonIndex == 0)
{
MyToDoView *detailViewController = [[MyToDoView alloc]
initWithNibName:#"MyToDoView" bundle:nil];
detailViewController.searchDate = selectedDate;
NSLog([NSString stringWithFormat:#"%#",detailViewController.searchDate]);
[detailViewController searchDateTableView];
[self.navigationController popViewControllerAnimated:YES];
[detailViewController release];
}
}
}
I hope this can help you....

Manage iPhone Calendar event from our application

The following is my code
NSLog(#"%#", thisEvent1.title);
EKEvent *thisEvent = [EKEvent eventWithEventStore:eventStore];
eventStore = [[EKEventStore alloc] init];
thisEvent = [EKEvent eventWithEventStore:eventStore];
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"yyyy-MM-dd:HH:mm"];
NSDate * date = [[NSDate alloc] init];
date = [dateFormatter dateFromString:[itsStartDate objectAtIndex:indexPath.row]];
[date retain];
thisEvent.startDate = [dateFormatter dateFromString:[itsStartDate objectAtIndex:indexPath.row]];
thisEvent.endDate = [dateFormatter dateFromString:[itsEndDate objectAtIndex:indexPath.row]];
thisEvent.notes = [itsNotes objectAtIndex:indexPath.row];
thisEvent.title = [itsTitle objectAtIndex:indexPath.row];
thisEvent.location = [itsLocation objectAtIndex:indexPath.row];
// thisEvent.allDay = TRUE;
NSMutableArray *myAlarmsArray = [[NSMutableArray alloc] init];
EKAlarm *alarm1 = [EKAlarm alarmWithRelativeOffset:-[[itsAlertOne objectAtIndex:indexPath.row] intValue]]; // 1 Hour
// EKAlarm *alarm2 = [EKAlarm alarmWithRelativeOffset:-86400]; // 1 Day
[myAlarmsArray addObject:alarm1];
//[myAlarmsArray addObject:alarm2];
thisEvent.alarms = myAlarmsArray;
[myAlarmsArray release];
//setting the Reuccurence rule
NSString * test1 = [itsRecurrenceFrequency objectAtIndex:indexPath.row];
BOOL isRecurrenceFrequencyExists = TRUE;
EKRecurrenceFrequency recurrenceFrequency;
if ([test1 isEqualToString: #"EKRecurrenceFrequencyDaily"]) {
recurrenceFrequency = EKRecurrenceFrequencyDaily;
}else if([test1 isEqualToString: #"EKRecurrenceFrequencyWeekly"]){
recurrenceFrequency = EKRecurrenceFrequencyWeekly;
}else if([test1 isEqualToString: #"EKRecurrenceFrequencyMonthly"]){
recurrenceFrequency = EKRecurrenceFrequencyMonthly;
}else if([test1 isEqualToString: #"EKRecurrenceFrequencyYearly"]){
recurrenceFrequency = EKRecurrenceFrequencyYearly;
}else{
isRecurrenceFrequencyExists = FALSE;
}
if(isRecurrenceFrequencyExists){
EKRecurrenceRule * recurrenceRule = [[EKRecurrenceRule alloc]
initRecurrenceWithFrequency:recurrenceFrequency
interval:[[itsRecurrenceInterval objectAtIndex:indexPath.row]intValue]
end:nil];
if (thisEvent.endDate != nil) {
EKRecurrenceEnd * end = [EKRecurrenceEnd recurrenceEndWithEndDate:thisEvent.endDate];
recurrenceRule.recurrenceEnd = end;
}else {
thisEvent.endDate = thisEvent.startDate;
}
thisEvent.recurrenceRule = recurrenceRule;
[recurrenceRule release];
}
[thisEvent setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:thisEvent span:EKSpanFutureEvents error:&err];
NSLog(#"%#", thisEvent.eventIdentifier);
[self.eventsList addObject:thisEvent];
In this code I have the Event id of my calendar event.
Now I want to update the event with the changes however Its not updating the previously created event.
Second I Need to know is it possible to capture the changes in calendar event they made in iPhone Calendar including deleting an event.
Can we delete the calendar event using the eventid?
Please help me if any one know the answer.. Thank you in advance.
Regards,
Dilip Rajkumar
Event can be created by this:
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
NSString* str = [[NSString alloc] initWithFormat:#"%#", event.eventIdentifier];
[arrayofCalIDs addObject:str];
You can delete the event using this:
EKEventStore* store = [[[EKEventStore alloc] init] autorelease];
EKEvent* event2 = [store eventWithIdentifier:[arrayofCalIDs objectAtIndex:i]];
if (event2 != nil) {
NSError* error = nil;
[store removeEvent:event2 span:EKSpanThisEvent error:&error];
}
[myPath release];
For Updating Event you cannot directly access any method as it is not available in iOS. So, you can do one thing for this.
(1) First remove the event with eventID.
(2) Create new Event using the same information of the last deleted event.