Loading url on UIWebView crashes with "unrecognized selector" exception - ios

I have built a view controller in my app whose only element is a UIWebView. I am trying to load a webpage on this uiwebview element with the following code, right after its view controller loads:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NetworkHelper *networkHelper = [NetworkHelper getInstance];
NSString *tocsUrl = [NSString stringWithFormat:#"%#%#", networkHelper.clientConfiguration[#"hdv_production_uri"],
#"/tocs?device=iOS"];
NSURL *url = [NSURL URLWithString:tocsUrl];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:urlRequest];
}
String tocsUrl is a valid http string (http://192.168.1.12:3000/tocs?device=iOS).
However, the line [self.webView loadRequest:urlRequest]; is crashing the app with the following exception:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView loadRequest:]: unrecognized selector sent to instance 0x170188fd0'
*** First throw call stack:
(0x186d86530 0x197d640e4 0x186d8d5f4 0x186d8a3ac 0x186c8ec4c 0x1000b5d18 0x18b594958 0x18b594668 0x18bc881d0 0x18b88f790 0x18b8aab50 0x18b8acf68 0x18b681c4c 0x18b5c8a14 0x18b5b1d08 0x18b5c83b0 0x18b587ec8 0x186d3ed98 0x186d3bd24 0x186d3c104 0x186c691f4 0x19008b6fc 0x18b5fa10c 0x1000e0ad8 0x1983e2a08)
libc++abi.dylib: terminating with uncaught exception of type NSException
self.webView is defined in the .h file as:
#property (strong, nonatomic) IBOutlet UIWebView *webView;
Any pointers on how to solve this crash will be highly appreciated.

Check your webView, you have assigned it to UIView instead of your UIWebView. You can also remove and re add the connection to your UIWebView and Interface Builder. You can use shift+option+right click to make sure that you're choosing right controller in IB

Related

BlocksKit crashing on Open In Dialogue

I have a view controller opening an 'Open-In' dialogue via a bar button item.
Calling code:
UIDocumentInteractionController *docInteraction = [[UIDocumentInteractionController alloc] init];
docInteraction.URL = location;
docInteraction.delegate = self;
if ([docInteraction presentOpenInMenuFromBarButtonItem:self.openInButton animated:YES])
self.openInController = docInteraction;
Dismissal code:
UIDocumentInteractionController *openIn = self.openInController;
if (openIn) {
[openIn dismissMenuAnimated:animated];
self.openInController = nil;
popupsDismissed = YES;
}
Sometime after the code is dismissed, the app crashes with this exception:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[A2DynamicUIPopoverControllerDelegate popoverController:animationCompleted:]: unrecognized selector sent to instance 0x1f82b4f0'
This is a BlocksKit defined interface, but I'm not using a BlocksKit class in thie particular case. 0x1f82b4f0 is a <A2DynamicDelegate: 0x1f82b4f0; protocol = UIPopoverControllerDelegate> but why BlocksKit is involved here at all is a mystery. Can someone give me some insight on how to fix the exception?
BlocksKit is a bit of a red herring. The dismissal code is deallocating the UIDocumentInteractionController too early here:
self.openInController = nil;
At the earliest, the deallocation should happen after the -documentInteractionControllerDidDismissOpenInMenu: delegate callback method.

App getting crashed when video is entered in full screen mode in iOS

I have an application where I am displaying a video on a view. But when the video is displayed it is getting crashed when I click on the full screen mode in iOS. This is my code:
-(void)viewDidLoad
{
MPMoviePlayerController *mc = [[MPMoviePlayerController alloc] initWithContentURL:nil];
mc.shouldAutoplay = NO;
mc.controlStyle = MPMovieControlStyleEmbedded;
NSURL *contentURL = [[NSBundle mainBundle] URLForResource:#"01 01. Welcome" withExtension:#"mov"];
mc.contentURL = contentURL;
[mc prepareToPlay];
mc.view.frame = self.test.bounds;
[self.test addSubview:mc.view];
self.testvideo = mc;
testvideo.fullscreen=YES;
}
I am adding player controller on to another view named test. When I click on the full screen buttons the app is getting crashed displaying error messages:
-[UIView trackRectForBounds:]: unrecognized selector sent to instance 0xa171ec0
2013-09-03 15:49:35.178 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView trackRectForBounds:]: unrecognized selector sent to instance 0xa171ec0'
Not sure why your app is crashing in the code snippet you've provided because the trackRectForBounds method is found on the UISlider class. Are you using a slider anywhere in your app ?
I'd suggest you to try the MPMoviePlayerViewController class instead of the MPMoviePlayerController class.
You can refer to this SO question for more details.

'NSUnknownKeyException' with UIWebview

I'm trying to create an app that starts from a main page with three buttons on it. Each button pressed will switch to another view. Each view is just a blank view with a UIWebView on it. Transitioning to each page works fine when there's nothing on it. However, when I add the UIWebview and all the correct code, the transition to the page causes the app to crash with this error message:
* Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key viewWeb.'
* First throw call stack:
(0x1c94012 0x10d1e7e 0x1d1cfb1 0xb7de41 0xaff5f8 0xaff0e7 0xb29b58 0x233019 0x10e5663 0x1c8f45a 0x231b1c 0xf67e7 0xf6dc8 0xf6ff8 0xf7232 0x259b 0x10e5705 0x192c0 0x19258 0xda021 0xda57f 0xd96e8 0x48cef 0x48f02 0x26d4a 0x18698 0x1befdf9 0x1befad0 0x1c09bf5 0x1c09962 0x1c3abb6 0x1c39f44 0x1c39e1b 0x1bee7e3 0x1bee668 0x15ffc 0x1e92 0x1dc5)
libc++abi.dylib: terminate called throwing an exception
I'm positive all the UIWebView code is correct since I tested the exact same code in a new app that just runs on a single view and has no transitions. But here's the code I'm using for the transition:
- (IBAction)floorCatalog:(id)sender {
UIViewController* floorLampsViewController = [[UIViewController alloc] initWithNibName:#"floorLampsViewController" bundle:[NSBundle mainBundle]];
[self.view addSubview:floorLampsViewController.view];
}
- (void)dealloc {
[_floorLampsButton release];
[_tableLampsButton release];
[_wallLampsButton release];
[super dealloc];
}
- (void)viewDidUnload {
[self setFloorLampsButton:nil];
[self setTableLampsButton:nil];
[self setWallLampsButton:nil];
[super viewDidUnload];
}
And here's the code I'm using for the web views:
#property (retain, nonatomic) IBOutlet UIWebView *viewWeb;
[self.viewWeb loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.bing.com"]]];
Any reason why this keeps happening? Thanks!
Is viewWeb hooked up to the UIWebView in Interface Builder? It looks like viewWeb wasn't initialized or something, and seeing you're using an IBOutlet it makes me think it's in your nib.

iOS Pin It SDK with no documentation and sample code

I'm trying to go through the basic tutorial on Pinterest's website.
the link for downloading documentation and iOS sdk doesn't provide documentation or sample code.there was only bundles in it
here is my viewcontroller.m file
#import "ViewController.h"
#import <Pinterest/Pinterest.h>
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton* pinItButton = [Pinterest pinItButton];
[pinItButton addTarget:self
action:#selector(pinIt:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:pinItButton];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)pinIt:(id)sender
{
Pinterest *pinterest = [[Pinterest alloc]initWithClientId:#"1431885" urlSchemeSuffix:#"pin1431885"];
[pinterest createPinWithImageURL:#"http://www.warrenphotographic.co.uk/photography/bigs/10122-Silver-and-red-kittens-white-background.jpg" sourceURL:#"http://placekitten.com" description:#"Pinning from Pin It Demo"];
}
#end
my code is fairly straight forward, i just couldn't get it running on my dev iphone
it kept throwing:
2013-06-06 17:17:27.787 Pinterest Testing[9403:907] -[__NSCFConstantString absoluteString]: unrecognized selector sent to instance 0x1c86c
2013-06-06 17:17:31.626 Pinterest Testing[9403:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString absoluteString]: unrecognized selector sent to instance 0x1c86c'
*** First throw call stack:
(0x32f4d3e7 0x3ac48963 0x32f50f31 0x32f4f64d 0x32ea7208 0x1a9f9 0x1a71d 0x34e47087 0x34e4703b 0x34e47015 0x34e468cb 0x34e46db9 0x34d6f5f9 0x34d5c8e1 0x34d5c1ef 0x36a745f7 0x36a74227 0x32f223e7 0x32f2238b 0x32f2120f 0x32e9423d 0x32e940c9 0x36a7333b 0x34db02b9 0x19f4d 0x3b075b20)
libc++abi.dylib: terminate called throwing an exception
You are sending your URLs as NSString objects. NSString doesn't have a -absoluteString method, this is what the crash log is telling you.
The declaration of the Pinterest method (in Pinterest.h) is as follows:
- (void)createPinWithImageURL:(NSURL *)imageURL
sourceURL:(NSURL *)sourceURL
description:(NSString *)descriptionText;
You need to send NSURL objects, not NSString's for the imageURL and sourceURL.
So for your case:
- (void)pinIt:(id)sender
{
NSURL *imageURL = [NSURL URLWithString:#"http://www.warrenphotographic.co.uk/photography/bigs/10122-Silver-and-red-kittens-white-background.jpg"];
NSURL *sourceURL = [NSURL URLWithString:#"http://placekitten.com"];
Pinterest *pinterest = [[Pinterest alloc]initWithClientId:#"1431885" urlSchemeSuffix:#"pin1431885"];
[pinterest createPinWithImageURL:imageURL
sourceURL:sourceURL
description:#"Pinning from Pin It Demo"];
}
A quick glance at the header reveals that you should be passing in NSURL instances as the values for the imageURL and sourceURL, so once you do that it will no longer complain about trying to invoke absoluteString on an NSString.
The readme docs are probably not up to date with the API. This happens. A lot.
You probably need to do:
[pinterest createPinWithImageURL:[NSURL URLWithString:#"http://www.warrenphotographic.co.uk/photography/bigs/10122-Silver-and-red-kittens-white-background.jpg"] sourceURL:[NSURL URLWithString:#"http://placekitten.com"] description:#"Pinning from Pin It Demo"];
The answers for the exceptions have already been given. I found the location of the sample project. You can download it from https://pinterest-ota-builds.s3.amazonaws.com/PinItDemo.zip
When you look at the sample file you can see that the urlSchemeSuffix is appended to your URL scheme. The following code is taken from the sample project:
[[Pinterest alloc] initWithClientId:#"1234" urlSchemeSuffix:#"prod"]
This means you have to register the following URL scheme in your app: pin1234prod.
This make make sure the callback works. You can also create the Pinterest client without suffix and the callback will also work with URL scheme pin1234

Trying to push to detail view with Xcode 4.2 iOS 5 from UIWebView

I have a ViewController embedded in a NavigationController. The ViewController has a UIWebView that I'm trying to capture links from. I'm able to intercept the links, but when I try to push the link content to a detail page, it seems to be firing a new Controller but it's invisible. If I click a link for a second time (or if I just click a second link) I see a back button pop up, but again the actual content of the new ViewController is not visible.
Here is the log output for the first link click:
2011-11-07 10:38:27.526 WGGB[43875:f803] *** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: <NSInternalInconsistencyException> Could not load NIB in bundle: 'NSBundle </Users/sonnyjitsu/Library/Application Support/iPhone Simulator/5.0/Applications/4B3D5152-4EA5-4C84-BB22-A774FCB8B6A7/WGGB.app> (loaded)' with name 'Detail View'
As you can see, it's "loading" the new view, but I see nothing in the simulator. Then the second time I click the same link (or click a new link) I see this in the log:
2011-11-07 10:38:30.605 WGGB[43875:f803] url is http://www.blahblahblah.com/mobile
The method in question is this:
-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = request.URL;
NSString *urlString = url.absoluteString;
NSRange page = [ urlString rangeOfString: #"/mobile" ];
if (page.location == NSNotFound) {
SingleStoryViewController *detailViewController = [[SingleStoryViewController alloc] initWithNibName:#"Detail View" bundle:nil];
NSString *requestURL =
[NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
[detailViewController.webView loadRequest:
[NSURLRequest requestWithURL:[NSURL URLWithString:requestURL]]];
[self.navigationController pushViewController:detailViewController animated:YES];
NSLog(#"url is %#", url);
return NO;
} else {
return YES;
}
}
Top of my SingleStoryViewController.m
#import "SingleStoryViewController.h"
#implementation SingleStoryViewController
#synthesize webView;
Entire SingleStoryViewController.h
#import
#interface SingleStoryViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIWebView *webView;
#end
Here is a link to an image of my Xcode storyboard, for what it's worth: http://i.imgur.com/I653v.png
I've been working on this for a good 14 to 16 hours now and I'm finally saying 'uncle' and asking for help. Any help would be appreciated, I'm very new to iOS programming so I apologize if there is something really stupid I'm missing.
As you can see, it's "loading" the new view...
That's not what the error says. The error says this:
Could not load NIB in bundle: [...] with name 'Detail View'
I'd start by checking the name of the .xib file in your app -- it sounds like it may not match the name you're using in the code.
Update: Per comments below, it turns out that this is app uses storyboards and doesn't contain any .xib files, so it's no surprise that attempting to load a view controller from a .xib produces an error. The correct way to load a view controller from a storyboard, when necessary, is to use UIStoryboard's -instantiateViewControllerWithIdentifier: method instead of UIViewController's -initWithNibName:bundle:.

Resources