UIWebView load crash [__NSCFDictionary _isChargeEnabled] - iphone

I use UIWebView to load this site http://www.xiami.com/song/1024665
sometimes my app crashes if I touch the view or play the audio in this site and sometimes it does not, why?
is it because html5? how to solve?
other website is no problem.
crash log is
* -[MPTransportButton _isChargeEnabled]: message sent to deallocated instance 0x20aa58d0
any help is much appreciated
---update---
I create a new view-base project, the code in ViewController is as following
This time, the crash log is
2011-08-16 18:11:25.450 WebTest[1291:707] -[__NSCFDictionary _isChargeEnabled]: unrecognized selector sent to instance 0x1ede0a10
2011-08-16 18:11:25.462 WebTest[1291:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary _isChargeEnabled]: unrecognized selector sent to instance 0x1ede0a10'
*** Call stack at first throw:
(
0 CoreFoundation 0x30ea764f __exceptionPreprocess + 114
1 libobjc.A.dylib 0x349c2c5d objc_exception_throw + 24
2 CoreFoundation 0x30eab1bf -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
3 CoreFoundation 0x30eaa649 ___forwarding___ + 508
4 CoreFoundation 0x30e21180 _CF_forwarding_prep_0 + 48
5 UIKit 0x30f232bd -[UIWindow warpPoint:] + 200
6 UIKit 0x30f0c1d5 _UIApplicationHandleEvent + 2404
7 GraphicsServices 0x30790e77 PurpleEventCallback + 666
8 CoreFoundation 0x30e7ea97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
9 CoreFoundation 0x30e8083f __CFRunLoopDoSource1 + 166
10 CoreFoundation 0x30e8160d __CFRunLoopRun + 520
11 CoreFoundation 0x30e11ec3 CFRunLoopRunSpecific + 230
12 CoreFoundation 0x30e11dcb CFRunLoopRunInMode + 58
13 GraphicsServices 0x3079041f GSEventRunModal + 114
14 GraphicsServices 0x307904cb GSEventRun + 62
15 UIKit 0x30f37d69 -[UIApplication _run] + 404
16 UIKit 0x30f35807 UIApplicationMain + 670
17 WebTest 0x00013425 main + 48
18 WebTest 0x000133f0 start + 40
)
terminate called after throwing an instance of 'NSException'
the source code in the project, not use MPMoviePlayerController this time or something else
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [self init];
return self;
}
- (id)init
{
if (self = [super initWithNibName:nil bundle:nil])
{
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIWebView *web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
[web loadRequest:[NSURLRequest requestWithURL:
[NSURL URLWithString:#"http://www.xiami.com/song/1024665"]]];
web.delegate = self;
[self.view addSubview:web];
[web release];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//[webView stringByEvaluatingJavaScriptFromString:#"window.scrollTo(0, 10);"];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
}

There's nothing wrong in code that you posted.
NSZombie says that there is a MPTransportButton somewhere in your code that was previously deallocated (released) and after that, somewhere else in your code, you want to do something with it.
I think that you do it in one of your UIWebView's delegate methods.
But... we need more code. Where do you alloc/init your MPMoviePlayerController? Or do you alloc/init a MPTransportButton?

Related

iOS5 to iOS4 crash - ViewControllers

Currently I am trying to make my app available for iOS4, to increase the number of people we can reach.
We have moved away from StoryBoard and are now using .xib files instead.
Right now, the only thing that is stopping this is this error:
2012-09-14 18:32:42.705 CrunchCalculator[7037:11303] -[CategoryViewController presentViewController:animated:completion:]: unrecognized selector sent to instance 0x6b42230
2012-09-14 18:32:42.707 CrunchCalculator[7037:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CategoryViewController presentViewController:animated:completion:]: unrecognized selector sent to instance 0x6b42230'
*** Call stack at first throw:
(
0 CoreFoundation 0x013625a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00ef1313 objc_exception_throw + 44
2 CoreFoundation 0x013640bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x012d3966 ___forwarding___ + 966
4 CoreFoundation 0x012d3522 _CF_forwarding_prep_0 + 50
5 CrunchCalculator 0x0002e560 +[OpenCalcViewController openCalcView:fromViewController:] + 8256
6 CrunchCalculator 0x0002fe0a -[CategoryViewController openCalc:] + 106
7 UIKit 0x002554fd -[UIApplication sendAction:to:from:forEvent:] + 119
8 UIKit 0x002e5799 -[UIControl sendAction:to:forEvent:] + 67
9 UIKit 0x002e7c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
10 UIKit 0x002e67d8 -[UIControl touchesEnded:withEvent:] + 458
11 UIKit 0x004e84de _UIGestureRecognizerSortAndSendDelayedTouches + 3609
12 UIKit 0x004e8c53 _UIGestureRecognizerUpdateObserver + 927
13 CoreFoundation 0x0134389b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
14 CoreFoundation 0x012d86e7 __CFRunLoopDoObservers + 295
15 CoreFoundation 0x012a11d7 __CFRunLoopRun + 1575
16 CoreFoundation 0x012a0840 CFRunLoopRunSpecific + 208
17 CoreFoundation 0x012a0761 CFRunLoopRunInMode + 97
18 GraphicsServices 0x014b61c4 GSEventRunModal + 217
19 GraphicsServices 0x014b6289 GSEventRun + 115
20 UIKit 0x00263c93 UIApplicationMain + 1160
21 CrunchCalculator 0x0000276a main + 170
22 CrunchCalculator 0x000026b5 start + 53
)
terminate called throwing an exception(lldb)
Usually I use this to open another view:
UIViewController *controller;
controller = [[CategoryViewController alloc]initWithNibName:#"CategoryViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:controller animated:YES];
[controller release];
But in this case I call a function from a different file (for efficiency) using this code:
#import "AllofTheFiles.h"
+ (void)openCalcView: (NSString *)nameOfView fromViewController:(UIViewController *)controller {
NSUserDefaults *saveSpot = [NSUserDefaults standardUserDefaults];
UIViewController *modalController;
if ([nameOfView isEqualToString:#"Tax"]) {
modalController= [[TAXViewController alloc]initWithNibName:#"TAXViewController" bundle:nil];
}else if ([nameOfView isEqualToString:#"Rent"]){
modalController= [[RENTViewController alloc]initWithNibName:#"RENTViewController" bundle:nil];
} //... cut other else if's to save space
modalController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[controller presentViewController:modalController animated:YES completion:nil];
[modalController release];
}
How can I fix this? Thanks in advance!
presentViewController:animated:completion: is available on iOS5 and above only, hence you get that crash.
Change the last part to:
modalController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
//do we support the new way of presenting a modal viewController?
if ([controller respondsToSelector:#selector(presentViewController:animated:completion:)])
{ //yes->so do it!
[controller presentViewController:modalController animated:YES completion:NULL];
}
else
{ //nope->we seem to be running on something prior to iOS5, do it the old way!
[controller presentModalViewController:modalController animated:YES];
}
[modalController release];
This will first check if the new way of presenting a viewController is supported. For making sure that this works fine in the future, as presentModalViewController: is marked as being deprecated, we only use that option if the new way is not available.
You may need to present a navcontroller, and/or use presentModalViewController, try the following:
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:modalController];
navController.modalPresentationStyle = UIModalPresentationPageSheet;
navController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[controller presentModalViewController:navController animated:YES completion:nil];
[modalController release];
[navController release];
The Till's solution is far the best.
But if, like me, you have numbers of present/DismissModalViewController: calls in your code, and doesn't want to duplicate the respondsToSelector test and is deprecated warnings over and over, just make UIViewController addition:
#implementation UIViewController (iOS4Compatibility)
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag {
if([self respondsToSelector:#selector(presentViewController:animated:completion:)])
[self presentViewController:viewControllerToPresent animated:flag completion:nil];
else
[self presentModalViewController:viewControllerToPresent animated:flag];
}
- (void)dismissViewControllerAnimated:(BOOL)flag {
if([self respondsToSelector:#selector(dismissViewControllerAnimated:completion:)])
[self dismissViewControllerAnimated:flag completion:nil];
else
[self dismissModalViewControllerAnimated:flag];
}
#end

release view controller and removing view

Quick question:
If I use
[someViewController.view addSubView:otherViewController.view];
to add a view. And then use
[otherViewController.view removeFromSuperView]
to remove the view, my app will crash when I call [otherViewController release]
The crash point is in the [super dealloc] line in my dealloc method of otherViewControll class implementation.
otherViewController is a reference to the view controller. I call release after its view has been removeFromSuperView'ed. By the time I call release, it's a valid pointer.
What am I doing wrong here?
otherViewController's dealloc class implementation
- (void)dealloc {
[popVC release];
[photoContainer release];
[photoView release];
[recordName release];
[recordIngr release];
[recordDesc release];
[recordPrice release];
[quantity release];
[pricingLabel release];
[increaseButton release];
[decreaseButton release];
[pricingTableVC release];
[pricingTable release];
[super dealloc]; // <--- crash point
}
updated: call trace
2011-06-04 00:35:05.110 MyApp[2308:207] -[__NSCFType _viewDelegate]: unrecognized selector sent to instance 0x4b6feb0
2011-06-04 00:35:05.124 MyApp[2308:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType _viewDelegate]: unrecognized selector sent to instance 0x4b6feb0'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dd75a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f2b313 objc_exception_throw + 44
2 CoreFoundation 0x00dd90bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d48966 ___forwarding___ + 966
4 CoreFoundation 0x00d48522 _CF_forwarding_prep_0 + 50
5 UIKit 0x00379051 -[UIViewController dealloc] + 128
6 MyApp 0x00009b26 -[RecordDetailViewController dealloc] + 797
7 MyApp 0x00004744 __-[RecordRootViewController bringUpNextRecordDetail:isNext:]_block_invoke_2 + 77
8 UIKit 0x002f7fb9 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 294
9 UIKit 0x002f7e4b -[UIViewAnimationState animationDidStop:finished:] + 77
10 QuartzCore 0x01d7b99b _ZL23run_animation_callbacksdPv + 278
11 QuartzCore 0x01d20651 _ZN2CAL14timer_callbackEP16__CFRunLoopTimerPv + 157
12 CoreFoundation 0x00db88c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
13 CoreFoundation 0x00db9e74 __CFRunLoopDoTimer + 1220
14 CoreFoundation 0x00d162c9 __CFRunLoopRun + 1817
15 CoreFoundation 0x00d15840 CFRunLoopRunSpecific + 208
16 CoreFoundation 0x00d15761 CFRunLoopRunInMode + 97
17 GraphicsServices 0x0172e1c4 GSEventRunModal + 217
18 GraphicsServices 0x0172e289 GSEventRun + 115
19 UIKit 0x002d5c93 UIApplicationMain + 1160
20 MyApp 0x0000200c main + 102
21 MyApp 0x00001f9d start + 53
)
terminate called after throwing an instance of 'NSException'
Update:
in -viewDidLoad, I have a gesture recognizer:
{
UISwipeGestureRecognizer *leftSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(showNextRecod:)];
[leftSwipeGestureRecognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[self.view addGestureRecognizer:leftSwipeGestureRecognizer];
[leftSwipeGestureRecognizer release];
}
I tried to use a Button to call -(IBAction) showNextRecod, it won't crash!! Only when I use the gesture to call the same method, it would crash
Regards
Leo
When you add a view controller's view as a subview to another view, you are only retaining it's view in memory and not the controller itself. Therefore, you must retain the view controller somewhere else (most likely make it a property)
Does that make sense?
In your gesture selector showNextRecod:
you should remove your target [pGestureRecognizer removeTarget:nil action:NULL];
#leo
You are just adding otherViewController.view in someViewController.view.
Just adding view not allocating it, then just remove it from your view.
Im not getting why you are using
[otherViewController release]
when you are not allocating it same view.
For sure you can log otherViewController.view count. See how much retain count for that view you are getting.

UIWebView loading html5-Video EXC_BAD_ACCESS crash

in our iPad-App we are using an UIWebView to load different sites from one domain some of them with a hml5-Video.
Sites without a Video do load perfectly. But when I'm loading a site containing htmlt5-video sometimes my app
crashes during the loading-process of the UIWebView with EXC_BAD_ACCESS and sometimes it does not. Whenever such a crash occurs it seems to happen at the point where the Video-Player is added into the site.
I did download the UICatalog-Example from Apple and just did change the Default-URL in the WebViewController-Class to a URL of a site containg html5-video. Same results ... sometimes crash sometimes no crash.
I also did create a New Project on Xcode (View-based Application - for iPad) and only did add a UIWebView to the new Projects ViewController. Again ... loading a site containing html5-video sometimes leads to a crash and sometimes not.
CODE FROM "NEW PROJECTS" VIEWCONTROLLER (IMPLEMENTATION):
- (void)viewDidLoad {
[super viewDidLoad];
self.myWebView = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 768, 1004)] autorelease];
self.myWebView.backgroundColor = [UIColor whiteColor];
self.myWebView.scalesPageToFit = YES;
self.myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.myWebView.delegate = self;
[self.view addSubview: self.myWebView];
[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.gelbeseiten.de/129103114849"]]];
//More Sites with HTML5-Videos ...
//[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.gelbeseiten.de/129103746403"]]];
//[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.gelbeseiten.de/129105233646"]]];
}
- (void)viewDidUnload {
[super viewDidUnload];
self.myWebView = nil;
}
- (void)viewWillDisappear:(BOOL)animated {
[self.myWebView stopLoading];
}
- (void)dealloc {
myWebView.delegate = nil;
[myWebView release];
[super dealloc];
}
CODE FROM "NEW PROJECTS" VIEWCONTROLLER (HEADER):
#interface WebViewTestViewController : UIViewController <UIWebViewDelegate> {
UIWebView *myWebView;
}
#property (nonatomic, retain) UIWebView *myWebView;
DEVICE LOGS:
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000098
Crashed Thread: 0
Thread 0 Crashed:
0 WebCore 0x34c7d09e WebCore::RenderLayer::clippingRoot() const + 110
1 WebCore 0x34c7cf2a WebCore::RenderLayer::childrenClipRect() const + 26
2 WebCore 0x34c7ce0c WebCore::RenderWidget::setWidgetGeometry(WebCore::IntRect const&) + 40
3 WebCore 0x34c5e0f8 WebCore::RenderWidget::updateWidgetPosition() + 320
4 WebCore 0x34ba0170 WebCore::RenderView::updateWidgetPositions() + 144
5 WebCore 0x34b97d16 WebCore::FrameView::performPostLayoutTasks() + 202
6 WebCore 0x34b8a6c0 WebCore::FrameView::layout(bool) + 2116
7 WebCore 0x34bc5244 WebCore::FrameView::forceLayout(bool) + 4
8 WebKit 0x302c0c24 -[WebHTMLView layoutToMinimumPageWidth:height:maximumPageWidth:adjustingViewSize:] + 136
9 WebKit 0x302c0b8e -[WebHTMLView layout] + 18
10 WebKit 0x302c26f2 -[WebHTMLView(WebInternal) _layoutIfNeeded] + 50
11 WebKit 0x302c2622 -[WebHTMLView(WebInternal) _web_layoutIfNeededRecursive] + 14
12 WebKit 0x302c251e -[WebHTMLView(WebPrivate) viewWillDraw] + 50
13 CoreFoundation 0x3581dfc0 -[NSObject(NSObject) performSelector:] + 12
14 CoreFoundation 0x35826d4a -[NSArray makeObjectsPerformSelector:] + 382
15 WebCore 0x34bb000c -[WAKView viewWillDraw] + 24
16 CoreFoundation 0x3581dfc0 -[NSObject(NSObject) performSelector:] + 12
17 CoreFoundation 0x35826d4a -[NSArray makeObjectsPerformSelector:] + 382
18 WebCore 0x34bb000c -[WAKView viewWillDraw] + 24
19 CoreFoundation 0x3581dfc0 -[NSObject(NSObject) performSelector:] + 12
20 CoreFoundation 0x35826d4a -[NSArray makeObjectsPerformSelector:] + 382
21 WebCore 0x34bb000c -[WAKView viewWillDraw] + 24
22 CoreFoundation 0x3581dfc0 -[NSObject(NSObject) performSelector:] + 12
23 CoreFoundation 0x35826d4a -[NSArray makeObjectsPerformSelector:] + 382
24 WebCore 0x34bb000c -[WAKView viewWillDraw] + 24
25 WebKit 0x302c24cc -[WebView(WebPrivate) viewWillDraw] + 56
26 WebCore 0x34bafec0 WebCore::TileCache::prepareToDraw() + 36
27 WebCore 0x34bafe6e -[TileLayer display] + 26
28 QuartzCore 0x31079fb0 CALayerDisplayIfNeeded + 176
29 QuartzCore 0x3106f56e CA::Context::commit_transaction(CA::Transaction*) + 214
30 QuartzCore 0x3106f37c CA::Transaction::commit() + 184
31 QuartzCore 0x31092f96 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 46
32 CoreFoundation 0x3580ac52 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 10
33 CoreFoundation 0x3580aac6 __CFRunLoopDoObservers + 406
34 CoreFoundation 0x358020c4 __CFRunLoopRun + 848
35 CoreFoundation 0x35801c80 CFRunLoopRunSpecific + 224
36 CoreFoundation 0x35801b88 CFRunLoopRunInMode + 52
37 GraphicsServices 0x320c84a4 GSEventRunModal + 108
38 GraphicsServices 0x320c8550 GSEventRun + 56
39 UIKit 0x341dc322 -[UIApplication _run] + 406
40 UIKit 0x341d9e8c UIApplicationMain + 664
41 WebViewTest 0x00002c24 0x1000 + 7204
42 WebViewTest 0x00002bd8 0x1000 + 7128
Can anybody give me an idea?
Thanks in advance, Florian
There is a little trick to override this crash. If you slightly scroll the webview just before the video content is loaded, the crash can be avoided. Before trying it out from code, try scrolling the webView a bit on device with your finger. It won't crash now.
In code, do something like this:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[webView stringByEvaluatingJavaScriptFromString:#"window.scrollTo(0, 10);"];
}
to simulate a scroll on the webview through javascript. The scroll value can be as low as 1, so the user won't notice the scroll at all.
Telling the webview to evaluate any JavaScript (or none at all) on webViewDidFinishLoad: seems work (albeit hacky).
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[webView stringByEvaluatingJavaScriptFromString:#""];
}
Seems I've solved this issue...
i've moved all HTML-5 video tags insertion in Javascript
function placeVideoTag() {
var val = '<video />';
var el = document.getElementById('video-id');
el.innerHTML = val;
}
And i'm calling JS in [UIWebView didFinishLoad]
- (void)webViewDidFinishLoad:(UIWebView *)aWebView {
[aWebView stringByEvaluatingJavaScriptFromString:#"placeVideoTag()"];
}
Works perfectly in my case.
Other suggestions didn't work for me.
I have exactly the same problem. no answer yet. Saw many others reports similar problems - iOS 4.2.1 only.
Basically, I have a UIView Controller with a webview as its subview, and load a URLRequest to a youtube link.
The first time I load the viewController, the console logs error "Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1 (8C148)/Symbols/System/Library/Internet Plug-Ins/QuickTime Plugin.webplugin/QuickTime Plugin (file not found).". I stop loading and release the viewController. The second time I re-load new viewController with the same request to that youtube link, now the app crashed with EXC_BAD_ACCESS
Thanks, for your posts!!! In my case it only works with different quite high offset-values for Portrait- and Landscape-Mode on iPad
(Portrait-Mode: greater than 60; Landscape-Mode: greater than 780):
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
if (self.interfaceOrientation == UIInterfaceOrientationPortrait ||
self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
[webView stringByEvaluatingJavaScriptFromString:#"window.scrollTo(0, 60);"];
} else if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[webView stringByEvaluatingJavaScriptFromString:#"window.scrollTo(0, 780);"];
}
webView.loadCounter--;
}
But with this solution my app crashes by double-tapping to zoom during the loading-process of a site.
I did subclass UIWebView to solve this problem (to prevent webView from zooming while loading):
.m:
#synthesize loadCounter;
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
CGPoint p = currentPoint;
NSTimeInterval t = currentTimestamp;
currentPoint = point;
currentTimestamp = [event timestamp];
if (CGPointEqualToPoint(p, point) &&
[event timestamp] - t < 0.2 && loadCounter > 0){
return self.superview;
}
return [super hitTest:point withEvent:event];
}
.h:
#interface NonDoubleTapableWhileLoadingWebView : UIWebView {
CGPoint currentPoint;
NSTimeInterval currentTimestamp;
NSInteger loadCounter;
}
#property (assign) NSInteger loadCounter;
And added a counter to determine the last "didFinish"-call and to reactivate the double-tapping possibility
(init loadCounter with 0)
- (void)webViewDidStartLoad:(UIWebView *)webView {
linkWebView.loadCounter++;
}

Crash presenting modal view controller

I have this crash. It is similar to other threads, but not the same.
I would like to show a modal view controller first the user goes to a specific view controller. Following the hints, I do that on - (void) viewDidAppear:(BOOL)animated, and apply a delay as I saw it's recommended.
- (void) viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self performSelector:#selector(presentMyModal) withObject:nil afterDelay:1];
}
- (void) presentModal{
ModalViewController *modal = [[[ModalViewController alloc] init] autorelease];
[self presentModalViewController:modal animated:YES];
}
Afterwards, ramdomly It crashes. I get this message in console:
<Warning>: *** Assertion failure in -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:], /SourceCache/UIKit/UIKit-1447.6.4/UIWindowController.m:186
Thu Feb 3 10:00:44 unknown MyApp[1830] <Error>: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempting to begin a modal transition from <UINavigationController: 0x454260> to <ModalViewController: 0x47af00> while a transition is already in progress. Wait for viewDidAppear/viewDidDisappear to know the current transition has completed'
*** Call stack at first throw:
(
0 CoreFoundation 0x3759dc7b __exceptionPreprocess + 114
1 libobjc.A.dylib 0x32d9bee8 objc_exception_throw + 40
2 CoreFoundation 0x3759dac3 +[NSException raise:format:arguments:] + 70
3 Foundation 0x351a3e73 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 62
4 UIKit 0x359e92a8 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 208
5 UIKit 0x359e8c98 -[UIViewController presentModalViewController:withTransition:] + 2792
6 UIKit 0x35a7b51c -[UIViewController _tryRecursivelyPresentModalViewController:withTransition:] + 116
7 UIKit 0x359e84c0 -[UIViewController presentModalViewController:withTransition:] + 784
8 UIKit 0x359e8060 -[UIViewController presentModalViewController:animated:] + 96
9 MyApp 0x0005d57f -[MyAppViewController presentMyModal] + 58
10 Foundation 0x351724db __NSFireDelayedPerform + 366
11 CoreFoundation 0x37552305 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 16
12 CoreFoundation 0x37551cd9 __CFRunLoopDoTimer + 988
13 CoreFoundation 0x37521a91 __CFRunLoopRun + 1184
14 CoreFoundation 0x3752150b CFRunLoopRunSpecific + 226
15 CoreFoundation 0x37521419 CFRunLoopRunInMode + 60
16 GraphicsServices 0x33e76d24 GSEventRunModal + 196
17 UIKit 0x3591d57c -[UIApplication _run] + 588
18 UIKit 0x3591a558 UIApplicationMain + 972
19 MyApp 0x0000e75f main + 50
20 MyApp 0x0000e6e8 start + 52
As you can see, I wait until view is appeared. Is this maybe an OS bug? It seems like it tries to present recursively other modal view controllers, provoquing crashes.
Thanks a lot.
Apart from me being picky in the comment, I thought I could as well help with this one as well. I think you need to search for the culprit somewhere else. I created a new project and a view controller with this snippet:
#import "VC1.h"
#implementation VC1
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self performSelector:#selector(presentModal) withObject:nil afterDelay:1.0];
}
- (void)presentModal {
static int colorChooser = 0;
VC1 *vc1 = [[[VC1 alloc] init] autorelease];
switch (colorChooser%2) {
case 0:
vc1.view.backgroundColor = [UIColor whiteColor];
break;
default:
vc1.view.backgroundColor = [UIColor blackColor];
break;
}
colorChooser++;
[self presentModalViewController:vc1 animated:YES];
}
#end
And it works flawlessly after being pushed on the navigation controller. It is recursively alternating between black and white views, tested both in the sim and on a 3G device.
Maybe you are doing some other view transitions due to some notifications or other asynchronic means? Either way you would need to share more of your code for anyone to tell where the problem is.
Our preferred solution is to use -[UIViewController presentViewController:animated:completion:] and do whatever the next action is (eg presenting another VC) in the completion block.
For example:
[self presentViewController:yourViewController animated:YES completion:^{
[yourViewController presentMyModal];
}];
This method was introduced in iOS 5.0.

My application doesn't open after trying to implement iAds!

I have been trying to implement iAds into my application, but this is what happens:
1.Tap on app
2.Loading Screen Displayed for a few seconds
3.App Crashes
This is whats returned:
2010-11-06 20:19:11.043 Vampire Quiz
Final[99722:207] Unknown class
AdViewController in Interface Builder
file. 2010-11-06 20:19:11.066 Vampire
Quiz Final[99722:207]
-[Vampire_Quiz_FinalViewController setBannerIsVisible:]: unrecognized
selector sent to instance 0x761c710
2010-11-06 20:19:11.409 Vampire Quiz
Final[99722:207] * Terminating app
due to uncaught exception
'NSInvalidArgumentException',
reason:
'-[Vampire_Quiz_FinalViewController
setBannerIsVisible:]: unrecognized
selector sent to instance 0x761c710'
* Call stack at first throw: ( 0 CoreFoundation
0x02a88b99 exceptionPreprocess + 185
1 libobjc.A.dylib
0x02bd840e objc_exception_throw + 47
2 CoreFoundation
0x02a8a6ab -[NSObject(NSObject)
doesNotRecognizeSelector:] + 187 3
CoreFoundation
0x029fa2b6 __forwarding + 966 4
CoreFoundation
0x029f9e72 _CF_forwarding_prep_0 + 50
5 Vampire Quiz Final
0x000027a2
-[Vampire_Quiz_FinalViewController viewDidLoad] + 601 6 UIKit
0x003715ca -[UIViewController view] +
179 7 Vampire Quiz Final
0x000021b1
-[Vampire_Quiz_FinalAppDelegate application:didFinishLaunchingWithOptions:]
+ 74 8 UIKit 0x002c7f27 -[UIApplication
_callInitializationDelegatesForURL:payload:suspended:]
+ 1163 9 UIKit 0x002ca3b0 -[UIApplication
_runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:]
+ 346 10 UIKit 0x002d43ec -[UIApplication
handleEvent:withNewEvent:] + 1958 11
UIKit
0x002ccb3c -[UIApplication sendEvent:]
+ 71 12 UIKit 0x002d19bf _UIApplicationHandleEvent +
7672 13 GraphicsServices
0x03368822 PurpleEventCallback + 1550
14 CoreFoundation
0x02a69ff4
CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION
+ 52 15 CoreFoundation 0x029ca807 __CFRunLoopDoSource1 + 215
16 CoreFoundation
0x029c7a93 __CFRunLoopRun + 979 17
CoreFoundation
0x029c7350 CFRunLoopRunSpecific + 208
18 CoreFoundation
0x029c7271 CFRunLoopRunInMode + 97 19
UIKit
0x002c9c6d -[UIApplication _run] + 625
20 UIKit
0x002d5af2 UIApplicationMain + 1160
21 Vampire Quiz Final
0x00002144 main + 102 22 Vampire
Quiz Final 0x000020d5
start + 53 ) terminate called after
throwing an instance of 'NSException'
sharedlibrary apply-load-rules all
(gdb)
P.S. I am new to development on the iPhone
Thanks
This is my code :
#implementation Vampire_Quiz_FinalViewController
- (IBAction)V;
{
Vork *V = [[Vork alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:V animated:NO];
}
- (IBAction)A;
{
About *A = [[About alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:A animated:NO];
}
- (IBAction)I;
{
Instructions *I = [[Instructions alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:I animated:NO];
}
- (void)dealloc {
[super dealloc];
}
- (void)viewDidLoad {
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0, -50);
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier320x50];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
[self.view addSubview:adView];
adView.delegate=self;
self.bannerIsVisible=NO;
[super viewDidLoad];
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
// banner is invisible now and moved out of the screen on 50 px
banner.frame = CGRectOffset(banner.frame, 0, 50);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
// banner is visible and we move it out of the screen, due to connection issue
banner.frame = CGRectOffset(banner.frame, 0, -50);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
#end
How can I fix it???
you are using self.bannerIsVisible but I can't see neither a synthesize for this nor setters and getters. Did you made a property with bannerIsVisible in your .h file?
To resolve this crash you should define the property in you header and add a #synthesize statement in your implementation.
Maybe you should start with something more basic to get to know the fundamental things like properties, synthesizers, compiler warnings (there should be one), debugging, and so on.
I don't want to be rude, but you won't learn much by using copied code you don't understand.
unrecognized selector sent to instance: this means the method for that class is not found. Check the class implementation.