I m working on a app with the NewsstandKit.frame work.
There was the NKAssetDownload request:
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:5.0];
_assetDownload = [self.issue addAssetWithRequest:request];
[_assetDownload downloadWithDelegate:self];
And the way I stop/pause the downloading it to cancel the connect:
NSURLConnection *con = [[self.issue.downloadingAssets objectAtIndex:0] downloadWithDelegate:self];
[con cancel];
And then there becomes the question,when I run the app again, there will show the wrong information about:
-[NKAssetDownload cover]: unrecognized selector sent to instance 0x6c69fc0
2012-10-26 15:49:39.257 MyMagazineDemoV0.0.1[3872:fb03] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NKAssetDownload cover]: unrecognized selector sent to instance 0x6c69fc0'
* First throw call stack:
(0x18b1022 0x1a42cd6 0x18b2cbd 0x1817ed0 0x1817cb2 0x10405 0x1018d 0x12f0a 0x127f8 0x3a2a 0x3d999b 0x338401 0x338a46 0x254e 0x310386 0x311274 0x320183 0x320c38 0x314634 0x179bef5 0x1885195 0x17e9ff2 0x17e88da 0x17e7d84 0x17e7c9b 0x310c65 0x312626 0x2292 0x2205)
terminate called throwing an exception
I duno wut does it mean,cuz I can not find the method called"cover" in NKAssetDownload.
Could anybody help me?:)
The correct procedure to start the download is as follows:
currentIssue = [library addIssueWithName:issueName date:issueDate];
NSURLRequest *urlReq = [NSURLRequest requestWithURL:[NSURL URLWithString:file_Url]];
NKAssetDownload *asset = [currentIssue addAssetWithRequest:urlReq];
[asset downloadWithDelegate:self];
When removing an issue, you should also remove the issue from Newsstand library:
NKIssue *issueToRemove = [[NKLibrary sharedLibrary] issueWithName:issueName];
if (issueToRemove) {
[[NKLibrary sharedLibrary] removeIssue:issueToRemove];
}
In addition to this u have to implement the NSURLConnectionDownloadDelegate methods
(void)connection:(NSURLConnection *)connection didWriteData:(long long)bytesWritten totalBytesWritten:(long long)totalBytesWritten expectedTotalBytes:(long long)expectedTotalBytes
(void)connectionDidFinishDownloading:(NSURLConnection *)connection destinationURL:(NSURL *)destinationURL
Try this. This works without error.
Related
I'm building a web browser from scratch and most everything works except for the most important thing. The browser will fail with the error sigabrt and, while I'm new to iPhone programming, I'm pretty sure this means that I'm not sending the URL correctly.
This is the code for loading the webpage by pressing a button.
- (IBAction)getURLButton:(NSString *)aString {
NSURL *URL = [NSURL URLWithString:aString];
NSURLRequest *URLRequest = [NSURLRequest requestWithURL:URL];
BOOL load = [addressBar webView: (goButton) shouldStartLoadWithRequest:URLRequest navigationType:UIWebViewNavigationTypeFormSubmitted];
if (load) {
error = nil;
[goButton loadRequest:URLRequest];
//currentURLString = [UIWebView stringByEvaluatingJavaScriptFromString:#"document.location.href"];
//It's not in Xcode? It continues to get an error after I write the above statement.
} else {
NSString *message = NSURLErrorFailingURLErrorKey;
NSLog(#"%#",message);
}
}
And this is the error message:
2013-02-14 16:49:28.724 WebBrowser[1265:c07] -[ViewController getURL:]: unrecognized selector sent to instance 0x716f1d0
2013-02-14 16:49:28.727 WebBrowser[1265:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController getURL:]: unrecognized selector sent to instance 0x716f1d0'
I know the errors there somewhere, I just don't know where. Help?
2013-02-14 16:49:28.724 WebBrowser[1265:c07] -[ViewController getURL:]: unrecognized selector sent to instance 0x716f1d0
2013-02-14 16:49:28.727 WebBrowser[1265:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController getURL:]: unrecognized selector sent to instance 0x716f1d0'
If you see your exception you are calling getURL: where as your method name is getURLButton:.
I have an app with four tabs. In each tab I connect to remote server using nsurlconnection, fetches the response and display accordingly. While testing the app, I get crashes randomly. If I try to reproduce the crash again I do not get crash. I do not understand what is root cause of the crash. I enable NSZombie,symbolicated crash logs,checked the memory leak but no luck.
I started the project in Xcode 3 and now I imported same project to Xcode 4.2, so are there any issues with compatibility of Xcode?
And I use the same name for nsurlconnection in all tabs like
In Tab 1 I defined nsurlconnection as conn and Tab 2 defined nsurlconnection as conn.
Does this definition causes any issue?
Please help me solve this random crashes
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: url];
conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(label != nil){
progressView = [[ProgressView showHUDAddedTo:self.tabBarController.view animated:YES] retain];
progressView.labelText = label;
}
[request release];
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSLog(#"didReceiveresponse");
if ([response isKindOfClass: [NSHTTPURLResponse class]]) {
if([(NSHTTPURLResponse *)response statusCode] == 200){
}
else{
//show Connection Error Alert
}
}
responseData = [[NSMutableData alloc]init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSLog(#"didReceiveData");
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[progressView hide:YES];
NSLog(#"didFail");
//show failed alert
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(#"didfinish loading");
if([responseData length] > 0)
{
//handles response data
}
}
My guess without seeing code, would be that in a tab your making an NSURLConnection and doing something with the result when it completes. If you change tab before the result is returned then it is causing it to crash.
You need to cancel the NSURLConnection when viewDidDisappear, or make sure that whatever code is run on completion of it doesn't contain anything that would cause a crash if the tab isn't visible (like setting a labels text).
The way I handle this, is have a separate class that performs the URL requests that sends a notification when it's complete. That way in your viewDidAppear method you set your viewController to listen for the notifications, and in the viewDidDisapper method you stop listening for the notifications. So if your view isn't visible when the URL request finishes, the notification is fired but nothing happens.
Could you provide the output of the console? It seems not to be an error from Xcode.
These type of error usually appear when you try to access a deallocated object.
i am sure you have tried Instruments with memory leak. give a try with instruments with zombie tool, you can find it easily in instruments library.
run your code with this tool and if this crash is because of any zombie object then you will easily able to detect the location.
it has helped me few times.
So after adding the following snippets to my source code, the application refuses to run and gives me a SIGABRT error:
CIALBrowserViewController.h
UIBarButtonItem *homeButtonItem;
CIALBrowserViewController.m
#interface CIALBrowserViewController ()
- (void)goHome:(id)sender;
..
homeButtonItem = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"home.png"]
style:UIBarButtonItemStylePlain
target:self
action:#selector(goHome:)] autorelease];
..
- (void)goHome:(id)sender {
NSURL *url = [NSURL URLWithString:#"http://google.ca/"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
}
The SIGABRT Error
2012-06-17 14:15:15.130 CIALBrowser[1753:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(0x354fa88f 0x378a1259 0x3544f1d7 0x5f8b 0x32f67c17 0x2a67 0x32f66cab 0x32f607dd 0x32f2eac3 0x32f2e567 0x32f2df3b 0x370ed22b 0x354ce523 0x354ce4c5 0x354cd313 0x354504a5 0x3545036d 0x32f5f86b 0x32f5ccd5 0x28df 0x2878)
terminate called throwing an exception(lldb)
Heres the full source code to CIALBrowserViewController.m: http://pastebin.com/uuUgi7Dc
In else section of if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad), there is no homeButtonItem alloced or inited, so homeButtonItem is nil. Then [buttons addObject:homeButtonItem]; will crash, because you are adding a nil object to array.
THe SIGABRT error suggests that somewhere in your code you use the method insertObject:atIndex: and use nil as the first parameter, which is not allowed, throwing an error. I went to your code on paste bin and did not see that method called there, so the error is likely in another file.
Hope this helps!
I have a UIViewController which is a UIWebViewDelegate and has a UIWebView inside of it. I am trying to load a particular URL
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[self.view addSubview:webView];
[webView release];
But the didFailLoadWithErrordelegate method is almost instantly called, and the error object is:
Did fail load with error: Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed. (NSURLErrorDomain error -999.)" UserInfo=0x1a66c0 {NSErrorFailingURLKey=www.somewebsite.com, NSErrorFailingURLStringKey=www.somewebsite.com}
However a short time after, you can see that the website loads just fine.
Why is the fail method being called? And how do I know when it has actually failed versus when the method was called regardless of if the website actually failed or not?
You can get this error when the page is instantly redirected via javascript or somehow else
You can avoid showing the error by answer from here: How do I fix NSURLErrorDomain error -999 in iPhone 3.0 OS
like
if ([error code] != NSURLErrorCancelled) { //show error alert, etc. }
but I don't know how to recognize where it was invoked.
So according to another StackOverflow question from a while back, the error code you're getting is being caused by a request being made before the previous request has been completed.
What may be happening is you are making multiple calls at the same time / very rapidly, and one is succeeding (so your web page loads) but the other is failing.
Use TapGesture on the web view using tapcount of 1.
Using a function for handling TapGesture, check if the URL returns status code of 200, if so, call the below function
-(void)animateme{
NSString *urlAddress = Connecting_URL
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.webview loadRequest:requestObj];
}
And, using delegate function,
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Device in offline" message:#"Please check your internet connection" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
[alert show];
}
Hope it helps :)
I'm currently trying to write an iPhone companion to a website that I'm developing. I'm trying to get JSON data from my website by making a controller a delegate of the NSURLConnection. Here's the problem though, I have an NSMutableData object named responseData initialized like so:
responseData = [NSMutableData dataWithLength:0];
And I want to append data as it comes:
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
However, this causes my app to crash and says in the console:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[__NSCFArray appendData:]: unrecognized selector sent to instance
0x6d0a640'
I'm pretty confident that appendData should be recognized, so I'm at a loss as to what the problem is here...
You have to retain the object:
responseData = [NSMutableData dataWithLength:0];
[responseData retain];
But that's not the common way of doing this. Simply use alloc/init:
responseData = [[NSMutableData alloc] init];
But don't forget to release in dealloc:
[responseData release];