Reputation: 517
hy there i have a bit of a problem. i have done an app that reads from xml and displays images. the app is working great on the simulator but sometimes the app does crash on iphone 4. What could it be ? Is there something wrong whit my treating or is the problem somewhere else ? the code is bellow. thank you
-(void)waiting{
// replace right bar button 'refresh' with spinner
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.center = CGPointMake(self.view.bounds.size.width/2, (self.view.bounds.size.height/2)-50);
spinner.hidesWhenStopped = YES;
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:spinner];
[spinner startAnimating];
// how we stop refresh from freezing the main UI thread
dispatch_queue_t downloadQueue = dispatch_queue_create("downloader", NULL);
dispatch_async(downloadQueue, ^{
// do our long running process here
[NSThread sleepForTimeInterval:0.2];
// do any UI stuff on the main UI thread
dispatch_async(dispatch_get_main_queue(), ^{
[self start];
[self picture];
[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(animate) userInfo:nil repeats:YES];
[spinner stopAnimating];
});
});
dispatch_release(downloadQueue);
}
-(void)start{
xmlElementObjects = [[NSMutableArray alloc] init];
parser = [[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.i-store.si/Storage/Images/app/galerija.xml"]];
[parser setDelegate:self];
[parser parse];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if(![elementName compare:@"PictureInfo"])
{
array = [[NSMutableArray alloc] init];
}
else if(![elementName compare:@"imageURL"])
{
currentAttribute = [NSMutableString string];
}
else if(![elementName compare:@"imageTitle"])
{
currentAttribute = [NSMutableString string];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if(![elementName compare:@"PictureInfo"])
{
}
else if(![elementName compare:@"imageURL"])
{
[array addObject:currentAttribute];
pictures=pictures+1;
currentAttribute = nil;
}
else if(![elementName compare:@"imageTitle"])
{
}
else if(![elementName compare:@"Pictures"])
{
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if(self.currentAttribute)
{
[self.currentAttribute appendString:string];
}
}
UPDATE: I try Bugsense and this is what i got:
CLASS:
SIGNAL
FILE:
_mh_execute_header +
0libobjc.A.dylib 0x31946fbc objc_msgSend + 15
1Foundation 0x31da161d __NSFireTimer + 144
2CoreFoundation 0x37e3aa63 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 14
3CoreFoundation 0x37e3a6c9 __CFRunLoopDoTimer + 364
4CoreFoundation 0x37e3929f __CFRunLoopRun + 1206
5CoreFoundation 0x37dbc4dd CFRunLoopRunSpecific + 300
6CoreFoundation 0x37dbc3a5 CFRunLoopRunInMode + 104
7GraphicsServices 0x3793afcd GSEventRunModal + 156
8UIKit 0x3524c743 UIApplicationMain + 1090
9My_app 0x0000273b _mh_execute_header + 5947
Upvotes: 0
Views: 412
Reputation: 65449
You cannot schedule the NSTimer on the main thread with GCD.
Use:
[NSTimer timerWithTimeInterval:target:selector:userInfo:repeats:]
.. to create the timer and:
[[NSRunLoop mainRunLoop] addTimer:forMode:]
.. to add it to the main runLoop.
For alternatives, check this answer from this question: Run repeating NSTimer with GCD?
Upvotes: 1