【发布时间】:2014-12-09 14:16:20
【问题描述】:
我的应用有一个小问题。
当我使用我的块时,应用程序冻结了很长时间(几乎 1 分钟),所以我们什么也做不了,所有的滚动/按钮/等都不起作用。
我想优化我的代码,让它运行得更快,并且用户不必等待 1 分钟
- (IBAction)exporter:(id)sender {
EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (!granted) {
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Accès aux calendrier" message:@"L'accès au calendrier est nécessaire pour utiliser cette fonctionnalité" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
EKEvent *event = [EKEvent eventWithEventStore:store];
Variables *objStatutCompte = [Variables getStatutCompte];
if([objStatutCompte.statutCompte isEqualToString:@"clt"])
{
NSString* titreEvent = [NSString stringWithFormat:@"Intervention avec %@", intervenantRecup];
event.title=titreEvent;
}
else if([objStatutCompte.statutCompte isEqualToString:@"slr"])
{
NSString* titreEvent = [NSString stringWithFormat:@"Intervention chez %@", clientRecup];
event.title=titreEvent;
}
NSString* lieuEvent = [NSString stringWithFormat:@"%@, %@", adresseClientRecup, villeRecup];
event.location=lieuEvent;
NSString* currentDay = [dateRecup substringWithRange:NSMakeRange(0,2)];
NSInteger jourCourant = [currentDay integerValue];
NSString* currentMonth = [dateRecup substringWithRange:NSMakeRange(3,2)];
NSInteger moisCourant = [currentMonth integerValue];
NSString* currentYear = [dateRecup substringWithRange:NSMakeRange(6,4)];
NSInteger anneeCourante = [currentYear integerValue];
NSString* dateDebut = [NSString stringWithFormat:@"%d-%d-%02d %@:00", anneeCourante, moisCourant, jourCourant, heureDebutRecup];
NSString* dateFin = [NSString stringWithFormat:@"%d-%d-%02d %@:00", anneeCourante, moisCourant, jourCourant, heureFinRecup];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
[dateFormatter setTimeZone:nil];
NSDate* dateD = [dateFormatter dateFromString:dateDebut];
NSDate* dateF = [dateFormatter dateFromString:dateFin];
event.startDate=dateD;
event.endDate=dateF;
NSMutableArray *myAlarmsArray = [[NSMutableArray alloc] init];
EKAlarm *alarm1 = [EKAlarm alarmWithRelativeOffset:-3600]; // 1 Hour
[myAlarmsArray addObject:alarm1];
event.alarms=myAlarmsArray;
[event setCalendar:[store defaultCalendarForNewEvents]];
NSError *err = nil;
[store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Evénement ajouté"
message:@"L'évenement a bien été ajouté"
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
[alert show];
}];
}
【问题讨论】:
-
你有没有发现它在哪条线上等了这么久?
-
@user623396,不,我不知道如何使用调试工具。
标签: ios objective-c iphone objective-c-blocks