0

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
pnuts
  • 58,317
  • 11
  • 87
  • 139
WildWorld
  • 517
  • 1
  • 5
  • 18
  • 2
    You should have had an error message or some sort of trace in the debugger - you should post that here, they are very useful (mandatory, even) to isolate the issue. – lxt Oct 16 '12 at 18:21
  • Problem is that I do not have iPhone4 for development. I send my app throught adhoc to my friend for test. – WildWorld Oct 16 '12 at 18:33
  • The simulator have debug messages too. – jcesarmobile Oct 16 '12 at 18:50
  • On simulator application work fine and does not crash only on iPhone4, maybe is problem whit Ram or something else... I do not know – WildWorld Oct 16 '12 at 19:01
  • Try setting up BugSense or Crittercism for some remote crash reporting. – Adis Oct 16 '12 at 23:51
  • You can have your friend send you the error logs and symbolicate them? – lxt Oct 17 '12 at 08:10
  • You might want to use english terms in your source code. Stuff like zazeni, polje and pocakaj are not really clear to me. – bmeulmeester Oct 25 '12 at 07:35

1 Answers1

1

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?

Community
  • 1
  • 1
Tieme
  • 62,602
  • 20
  • 102
  • 156