I don't know the reason but as soon as i get from a UITextField some data, like "Facebook", i call this code
- (IBAction)searchForAddress:(id)sender
{
[self loadRequestFromAddressField:_addressField];
}
- (void)loadRequestFromAddressField:(id)addressField
{
NSString *urlString = [addressField text];
[self loadRequestFromString:urlString];
}
- (void)loadRequestFromString:(NSString*)urlString
{
NSString *composedUrlString = [NSString stringWithFormat:#"http://www.google.com/search?q=%#",urlString];
NSURL *url = [NSURL URLWithString:composedUrlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:urlRequest];
}
Now the UIWebView loads correctly giving me the result of the google search, the problem is that when i try to enter some link it crashes giving me this error
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WeBViewController searchURL:]: unrecognized selector sent to instance 0x8f38540'
What could be the problem??
Please check if your WeBViewController have methode name searchURL
it is very basic error.
It means you are calling method on instance of WeBViewController which is not implemented in it.
If you are still unable to fix this issue you can paste your code in question so we can take look at it.
Related
Sometimes my App works fine but sometimes it fails with this error:
* WebKit discarded an uncaught exception in the webView:didFinishLoadForFrame: delegate: * -[__NSArrayM objectAtIndex:]: index 6 beyond bounds [0 .. 5]
I have found some other Questions about exceptions in WebKit but no one with the NSRangeException.
My Code:
- (id) init {
myWebView = [[UIWebView alloc] init];
myWebView.delegate = self;
[myWebView stopLoading];
return self;
}
- (void)loadUrl:(NSString *)urlAddress {
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[myWebView stopLoading];
[myWebView loadRequest:requestObj];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
if (!myWebView.isLoading) {
[myWebView stopLoading];
if (selectedInfo == LOADTable) {
NSString *html = [NSString stringWithFormat:#"%#",[myWebView stringByEvaluatingJavaScriptFromString:#"document.body.innerHTML"]];
[myWebView stopLoading];
[self parseTable:html];
}
}
}
Do anybody have an idea how to solve this error.
The UIWebView is not shown on any UIView. Just for loading the HTML.
Could you please post the code of parseTable: method. Also, before calling parseTable: method, please ensure you put a nil check on your html string. And inside parseTable: method, please make sure you are putting safe check on NSArray count before calling objectAtIndex: method on it. Looks like you are trying to access 7th item (index 6) from NSArray which contains only 6 items (max index 5).
I think the crash occures in [self parseTable:html]; so check breakpoint to this line and confirm. if it is true then debug inside this method
Hi, I'm new to the iOS app development I have created an app with two ViewController for the the second controller have created on class in called video controll view. Everything is fine but when I click the play I'm getting warning like this I don't what is this can anyone please help me on that I'm stuck here for long time.
2013-12-25 10:10:12.890 politicalapp[346:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
This is the code I have put for the video player:
- (IBAction)play:(UIButton *)sender {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"d" ofType:#"mp4"]];
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc]initWithContentURL: url];
[self presentMoviePlayerViewControllerAnimated:player];
player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;[player.moviePlayer play];
player = Nil;
}
#end
Your problem is that pathForResource is returning nil. There can be a number of causes of this. Try changing it to:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"d.mp4" ofType:nil]];
If that doesn't solve it, just search the multiple of questions on stackoverflow named "Path for resource returns nil" and trouble shoot based on the various issues already discussed.
I am developing a simple testing app for iPhone. I want to click a button to change the URL of webview, then load the new URL. Here is my code:
NSString *nurl = [NSString stringWithFormat: #"http://www.abc.com/abc.aspx?SN=%#&fdate=%#&tdate=%#", SNstr, fDate, tDate];
NSLog(#"################: %#", nurl);
NSURL *url = [NSURL URLWithString:nurl];
NSLog(#"################: %#", url);
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[Logs loadRequest:req];
It is working well inside viewDidLoad.
I move it into a button:
-(IBAction)CheckLog:(id)sender
{
// codes here
}
When I press the button, it gives nurl's value correct, but url's value is null. So nothing is changed on the UIWebView Logs.
Why could this be, when the code runs correctly in viewDidLoad?
your button action will be like this...
-(IBAction)CheckLog:(id)sender
{
[[NSURLCache sharedURLCache] removeAllCachedResponses];
NSString *nurl = [NSString stringWithFormat: #"http://www.abc.com/abc.aspx?SN=%#&fdate=%#&tdate=%#", SNstr, fDate, tDate];
NSURL *url = [NSURL URLWithString: [nurl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ];
// NSURL *theURL = [NSURL URLWithString:#"https://www.google.co.in/"]; // Your new URL
[self.myWebView loadRequest:[NSURLRequest requestWithURL:url]];
}
The first thing to check is that the method is definitely being called. Are your NSLog statements being printed? If not, check that you have connected the button to the IBAction correctly in Interface Builder.
I can't see anything in your code that is immediately jumping out to me as incorrect, so your best bet is to set a breakpoint at the start of the method and step through it line-by-line, checking the values of each variable as you go.
I cannot seem to get this link:
https://api.soundcloud.com/tracks/54507667/stream
to work with the AVAudioPlayer. I have tested it in a Souncloud API started project and it seems to work just fine, however, when I try to implement it on my own it doesn't seem to work.
The error I get:
unrecognized selector sent to instance 0x9245d40
2013-01-04 17:56:04.699 CollectionViewTest[17023:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString absoluteURL]: unrecognized selector sent to instance 0x9245d40'
* First throw call stack:.....
The code:
NSURL *streamURL = [NSString stringWithFormat:#"%#",
allDataDictionarySound[#"stream_url"], nil];
NSLog(streamURL);
NSURLRequest *request = [NSURLRequest requestWithURL:streamURL];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
connectionPlay = [[NSURLConnection alloc] initWithRequest:request delegate:self];
NSLog(#"test:");
NSError *playerError;
player = [[AVAudioPlayer alloc] initWithData:streamData error:&playerError];
NSLog(#"test:2");
The streamURL prints as expected, and then the program crashes.
the tests are not printed.
When everything else is commented out, and the NSURLRequest is left, it still crashes.
When I comment the whole block of code out, everything compiles and runs.
I now have attempted this:
NSData *_objectData = [NSData dataWithContentsOfURL:streamURL];
NSError *error;
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithData:_objectData error:&error];
audioPlayer.numberOfLoops = 0;
audioPlayer.volume = 1.0f;
[audioPlayer prepareToPlay];
if (audioPlayer == nil)
NSLog(#"%#", [error description]);
else
[audioPlayer play];
This also returns the length error, I am at a loss on what could be causing this...
2013-01-05 13:46:16.536 CollectionViewTest[28224:c07] -[NSURL length]: unrecognized selector sent to instance 0x928a470
2013-01-05 13:46:16.546 CollectionViewTest[28224:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL length]: unrecognized selector sent to instance 0x928a470'
* First throw call stack:
streamURL is an NSString - not a NSURL
try:
NSURL *streamURL = [NSURL URLWithString: [NSString stringWithFormat:#"%#",
allDataDictionarySound[#"stream_url"], nil]];
I'm also not clear where the variable "streamData" is coming from (or what you expect to be in it).
The NSURLConnection is loading the data from the request asynchronously. It looks like you are assuming that the data is loaded synchronously and is available when you're initializing the "player" object. The data will (mostly likely) not be there when player is initialized.
NSURL *url = [NSURL URLWithString:#"http://locationofurlonlocalhost.mp4"];
...
NSMutableURLRequest *req;
req = [NSMutableURLRequest requestWithURL:url // <-- CRASH IS HERE!! thx to a breakpoint stepthrough
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:30.0];
a log of url will result in:
Printing description of url:
<NSURLRequest http://locationofurlonlocalhost.mp4>
the crash will log
-[NSURLRequest absoluteURL]: unrecognized selector sent to instance 0x88003e0
The URL looks just fine so I'm not sure what's going on. Could this happen because the url is unreachable the simulator? I can connect to the url on the sim's safari as well as my desktop safari. What should I do?
** EDIT **
it's been determined that the url object is being released too early. In the ... the url is passed to a different selector and then the rest of the code takes place there. How can I force retain the url? I have already tried:
__strong NSURL *url = [[NSURL alloc] initWithString:#"http://locationofurlonlocalhost.mp4"];
This most definitely looks like your url has been released somehow. If you print the description of the url variable and wind up with an NSURLRequest, then you're looking at freed up memory.
Try using alloc / initWithString: as a troubleshooting step.