0

As subject says i can run my application on device in debug mode without any problem, but when i try to run on test device (ad hoc distribution) there're some section (not all) that don't work.

The application dowloads json data from server and showed parsed data to user, (texts, videos, ecc).

To comunicate with server i've used ASIFormDataRequest every where in the application.

Any ideas?

Thanks!

Some code:

NSMutableString *url = [[NSMutableString alloc] initWithString:@"http://url"];
NSURL *urlElaborazioneDati = [NSURL URLWithString:url];

__weak __block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:urlElaborazioneDati]; 
[request setCompletionBlock:^{
    __weak NSString *jsonData = [request responseString];
    NSArray *jsonArray = [jsonData JSONValue];scrollView = [[UIScrollView alloc] init];
    scrollView.frame = CGRectMake(0.0, 70.0, 320.0, 312.0);
    scrollView.backgroundColor = [UIColor colorWithRed:1 green:0.5 blue:0 alpha:0];

    scrollView.contentSize = CGSizeMake(320.0,marginTop*[jsonArray count]);
    [self.listaVideo addSubview:scrollView];

    for (int i=0; i<[jsonArray count]; i++) {
NSString *key = [NSString stringWithFormat:@"%d",i];
        NSArray *elemento = [jsonArray valueForKey:key];

        UIView *item = [[UIView alloc] initWithFrame:CGRectMake(148.0, (marginTop*i), 162.0, 67.0)];
        item.backgroundColor = [UIColor colorWithRed:1 green:0.5 blue:0 alpha:0];
        [scrollView addSubview:item];

        UILabel *titoloVideo = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 162, 20)];
        titoloVideo.backgroundColor = [UIColor colorWithRed:1 green:0.5 blue:0 alpha:0];
        titoloVideo.textColor = [UIColor whiteColor];
        titoloVideo.font = [UIFont boldSystemFontOfSize:17];
        [titoloVideo setText:[elemento valueForKey:@"titolo"]];
        [item addSubview:titoloVideo];

        UITextView *testoVideo = [[UITextView alloc] initWithFrame:CGRectMake(0, 30, 162, 37)];
        testoVideo.backgroundColor = [UIColor colorWithRed:1 green:0.5 blue:0 alpha:0];
        testoVideo.textColor = [UIColor whiteColor];
        testoVideo.font = [UIFont boldSystemFontOfSize:13];
        testoVideo.textAlignment = UITextAlignmentLeft;
        testoVideo.editable = NO;
        [testoVideo setContentInset:UIEdgeInsetsMake(-10, -7, 0, 0)];
        [testoVideo setText:[elemento valueForKey:@"testo"]];
        [item addSubview:testoVideo];

        [self embedYouTube:[elemento valueForKey:@"url"] frame:CGRectMake(10, (marginTop*i), 128, 67)];
}

}];
[request setFailedBlock:^{
    NSError *responseerror = [request error];

    NSString *responseerrorstring = [NSString stringWithFormat:@"%@",responseerror];

    UIAlertView *error = [[UIAlertView alloc] initWithTitle: @"Errore connessione"
                                       message: responseerrorstring
                                      delegate: self
                             cancelButtonTitle: @"Ok"
                             otherButtonTitles: nil];
    [error setTag:1];
    [error show];
}];

Then in embedYouTube:

- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame {

NSString *embedHTML = @"\
<html><head>\
<meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = %0.0f\"/></head>\
<body style=\"background:#fff;margin-top:0px;margin-left:0px\">\
<div><object width=\"%0.0f\" height=\"%0.0f\">\
<param name=\"movie\" value=\"%@\"></param>\
<embed src=\"%@\"\
type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"%0.0f\" height=\"%0.0f\"></embed>\
</object></div></body></html>";

NSString *html = [NSString stringWithFormat:embedHTML, frame.size.width, frame.size.width, frame.size.height, urlString, urlString, frame.size.width, frame.size.height];
//NSLog(@"%0.0f, %0.0f, %@",frame.size.width, frame.size.height, html);
UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
[videoView loadHTMLString:html baseURL:nil];
[scrollView addSubview:videoView];

}

This is one of the section that seem not working in ad hoc distribution...


If this can help someone in the same situation, here the answer of Apple Developer Technical Support:

When making an Ad Hoc build, by default Xcode applies more optimizations when compiling the project. For more information, see https://developer.apple.com/library/ios/qa/qa1764/.

It's not that uncommon for optimizations to expose bugs in code. Usually this is undefined behavior (like stomping on memory, e.g. by copying a string into a buffer that is too small to hold it) causing problems when before the code accidentally worked; or ARC being more aggressive about releasing objects early, which may expose an __unsafe_unretained crash, or cause __weak objects to disappear earlier.

Do you know if your completion blocks were ever called? If you add NSLog(@"%s:%d", func, LINE); in your code, do you see method called that you expect?

Do you know if the download started? Was the request object deallocated sooner than you expected?

To figure out what's going wrong, you'll need to zero in on exactly the thing that's failing.

If the problem only reproduces when an IPA is installed via iTunes, you'll need to use NSLog() to trace the program flow, and examine the actual values of variables, to see what isn't behaving the way you expect. For more information, see "Debugging Deployed iOS Apps" http://developer.apple.com/library/ios/qa/qa1747/.

You might also try changing your build settings to use the same optimizations (usually "Fastest, Smallest -Os") when making a Debug build as when making a Release build. This way you can use the debugger, although be aware that the optimizations will make it somewhat unreliable. When in doubt, fall back on NSLog().

Best regards,

...

Lucabro
  • 525
  • 3
  • 9
  • 30
  • What does not work? Any error messages? Crashes? Logs? – E. Lüders Sep 18 '12 at 14:04
  • 1
    Yeah, this question is insanely vague. – borrrden Sep 18 '12 at 14:05
  • This is the problem, no crashes no message of any kind, no freeze, only view without their contains the data request are normal, using block,nothing special, and parsed with JSONValue... No problem in debug mode with external device, in ad hoc distribution some view are empty... I try to post some code, but i repeat there's nothing special – Lucabro Sep 18 '12 at 14:21
  • When the app is ditribuited on a device there's a way to make a log file? – Lucabro Sep 18 '12 at 14:36
  • Let me guess. Your `url` is `127.0.0.1` or `localhost` ? – ldiqual Sep 18 '12 at 14:56
  • no, is the url of a web server, and the app is composed by 5 main views, only 2 of them don't work (no data loaded).. Thankyou for the response anyway – Lucabro Sep 18 '12 at 14:59
  • I've found a response to my bug here: [ASIHTTPRequest / ASIFormDataRequest - referencing request object within blocks under ARC][1] [1]: http://stackoverflow.com/questions/8859649/asihttprequest-asiformdatarequest-referencing-request-object-within-blocks-u/8874812#8874812 – Lucabro Sep 21 '12 at 15:55

0 Answers0