Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

primedime

macrumors member
Original poster
Mar 21, 2011
66
0
Ft. Lauderdale, FL
I have two applications in which I use a UIwebView in order to show the mobile youtube page.... I am not sure how to really explain the actual error because this is the first time I am seeing this type of problem... The thing is that it only happens if I try to open that webview multiple times in one session. If I just open it one time it works fine, the second I launch it again it freezes and crashes.... it says Thread1: Program received signal "EXC_BAD_Access".

Here is the code, any help is much appreciated:

Code:
#import "YoutubeViewController.h"
#import "MainViewController.h"

@implementation YoutubeViewController

@synthesize myWebView;
@synthesize toolbar;

- (void)loadWebPageWithString:(NSString *)urlString
{
	NSURL *url = [NSURL URLWithString:urlString];
	NSURLRequest *request = [NSURLRequest requestWithURL:url];
	[myWebView loadRequest:request];
}

-(IBAction)back
{
	[self.parentViewController dismissModalViewControllerAnimated:YES];
}

-(IBAction)goHome 
{
    NSString *urlAddress = @"http://m.youtube.com/primedime21";
    
    NSURL *address = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:address];
    [myWebView loadRequest:requestObj];
}

-(IBAction)reload
{
	NSLog(@"reload");
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewWillDisappear:(BOOL)animated
{
	[myWebView stopLoading];
}

- (void)dealloc
{
    [myWebView release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
	
	[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://m.youtube.com/primedime21"]]];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	
	return YES;
}

@end
 

nickculbertson

macrumors regular
Nov 19, 2010
226
0
Nashville, TN
I have had the same problem before with putting youtube user pages in an app. I think the only solution is to work around the problem... embed the videos you want to play or have the app navigate to the youtube app for playback.

Nick
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
EXC_BAD_ACCESS is caused by over-released or under-retained objects. You should probably post the code where you present your YoutubeViewController, since that's where your issue seems to be popping up.
 

primedime

macrumors member
Original poster
Mar 21, 2011
66
0
Ft. Lauderdale, FL
Here is my main view:

Code:
#import "MainViewController.h"

@implementation MainViewController

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
}
*/

-(IBAction)switchView{
   
    YoutubeViewController *youtube = [[YoutubeViewController alloc] 
                                      initWithNibName:@"YoutubeViewController" bundle:nil];
    youtube.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentModalViewController:youtube animated:YES];
    [youtube release];
    
    FacebookViewController *facebook = [[FacebookViewController alloc]
                                        initWithNibName:@"FacebookViewController" bundle:nil];
    facebook.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentModalViewController:facebook animated:YES];
    [facebook release];
    
}


// set up email button
- (IBAction)email:(id)sender;
{
    MFMailComposeViewController *mailComposer = 
    [[MFMailComposeViewController alloc] init];
    mailComposer.mailComposeDelegate = self;
    
    if ([MFMailComposeViewController canSendMail]) {
        [mailComposer setToRecipients:[NSArray 
                                       arrayWithObjects:@"rjossfolk@gmail.com", nil]];
        [mailComposer setSubject:@"Inquery from mobile app"];
        [mailComposer setMessageBody:nil isHTML:NO];
        [self presentModalViewController:mailComposer animated:YES];
    }
}

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    [self dismissModalViewControllerAnimated:YES];
    
    if (result == MFMailComposeResultFailed) {
        UIAlertView *alert = [[UIAlertView alloc] 
                              initWithTitle:@"Unable to send mail" 
                              message:@"Please,check your internet connection and try again"
                              delegate:self 
                              cancelButtonTitle:@"OK" 
                              otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}


//Flip side
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
    [self dismissModalViewControllerAnimated:YES];
}

- (IBAction)showInfo:(id)sender
{    
    FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
    controller.delegate = self;
    
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:YES];
    
    [controller release];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations.
    return YES;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload
{
    [super viewDidUnload];

    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)dealloc
{
    [super dealloc];
}

@end

Here is the YoutubeViewController:

Code:
#import "YoutubeViewController.h"
#import "MainViewController.h"

@implementation YoutubeViewController

@synthesize myWebView;
@synthesize toolbar;

- (void)loadWebPageWithString:(NSString *)urlString
{
	NSURL *url = [NSURL URLWithString:urlString];
	NSURLRequest *request = [NSURLRequest requestWithURL:url];
	[myWebView loadRequest:request];
}

-(IBAction)back
{
	[self.parentViewController dismissModalViewControllerAnimated:YES];
}

-(IBAction)goHome 
{
    NSString *urlAddress = @"http://m.youtube.com/primedime21";
    
    NSURL *address = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:address];
    [myWebView loadRequest:requestObj];
}

-(IBAction)reload
{
	NSLog(@"reload");
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewWillDisappear:(BOOL)animated
{
	[myWebView stopLoading];
}

- (void)dealloc
{
    [myWebView release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
	
	[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://m.youtube.com/primedime21"]]];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	
	return YES;
}

@end


Let me know if you need to see anything else.... Thanks a lot!
 

primedime

macrumors member
Original poster
Mar 21, 2011
66
0
Ft. Lauderdale, FL
If you take a look at that image I have 4 buttons at the bottom not including the info button. for the youtube, facebook and linkedin I want to open them in a UIWebView and the Twitter button will open a twitter feed I have made in my previous application.... The switchView is the event I am using to switch from the main view to the views for youtube and facebook... I think i am missing an IF statement in there which I am looking up currently but none the less my youtubeviewcontroller crashes if I open it more than once in a session.... Am I clear enough in this description?



Screen shot 2011-04-17 at 12.13.38 PM by primedime, on Flickr
 

chown33

Moderator
Staff member
Aug 9, 2009
10,751
8,423
A sea of green
Have you run your code using Instruments, with zombies enabled?

That should almost always be the first step when getting this kind of error.
 

primedime

macrumors member
Original poster
Mar 21, 2011
66
0
Ft. Lauderdale, FL
To be totally honest with you I have never used instruments before, I am pretty new to xcode and still learning. I have tried to open it before but didn't know what to do next.... I have troubles reading the resources as well since I have never done any coding before I started a few months ago but I am getting better at understanding the terminology.... I plan on looking in to instruments though because I have an app ready for the store but when I put it on my phone it has a few crashes here and there.... This is my second app now so hopefully soon I can use instruments...
 

chown33

Moderator
Staff member
Aug 9, 2009
10,751
8,423
A sea of green
To be totally honest with you I have never used instruments before, I am pretty new to xcode and still learning. I have tried to open it before but didn't know what to do next.... I have troubles reading the resources as well since I have never done any coding before I started a few months ago but I am getting better at understanding the terminology.... I plan on looking in to instruments though because I have an app ready for the store but when I put it on my phone it has a few crashes here and there.... This is my second app now so hopefully soon I can use instruments...

It's not overly difficult.
http://meandmark.com/blog/2010/09/using-nszombie-with-instruments/

http://developer.apple.com/library/...mentsUserGuide/AboutTracing/AboutTracing.html
 

primedime

macrumors member
Original poster
Mar 21, 2011
66
0
Ft. Lauderdale, FL
Cool, I am going to run it right now and see what's up... I already added all the other views and attached them to all the other buttons... The only view giving me trouble is the YoutubeViewController.....
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
The error shown by Build and Analyze is correct. Your code shows a leak of the mailcomposer. There should be a release for that view controller at the end of the method. However that memory leak shouldn't cause a crash.

What line in your code is causing the bad access crash?
 

primedime

macrumors member
Original poster
Mar 21, 2011
66
0
Ft. Lauderdale, FL
The error shown by Build and Analyze is correct. Your code shows a leak of the mailcomposer. There should be a release for that view controller at the end of the method. However that memory leak shouldn't cause a crash.

What line in your code is causing the bad access crash?

I added [mailComposer release]; to it and it still shows a leak. Any ideas on what exactly I am missing?

And the error is in the main.m file

Code:
#import <UIKit/UIKit.h>

int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil); <-- here is the error
    [pool release];
    return retVal;
}


Also, how would I go about having it open the youtube app to my youtube channel? Thanks guys!
 

nickculbertson

macrumors regular
Nov 19, 2010
226
0
Nashville, TN
perhaps you could load the youtube page in the mainview's viewdidload method and make it hidden until the youtube button is pushed (without opening a second xib). This way the page is only loaded once with the viewdid of your mainview. I've never tried it but its worth a shot.

Nick
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.