Objective-C delegate incompatible type - objective-c

I am using http://www.vfr.org/, pdf viewer, and I try to add a button to open PDF in IBOOK.
I added the button and action to it, but I stuck t the moment when I want open ibooks application with this pdf.
I tried 2 solutions:
button tapped action:
NSURL *fileURL = document.fileURL;
NSString *fileName = document.fileName; // Document
[[UIApplication sharedApplication] openURL:fileURL];
It opens the IBOOKS but the PDF never gets loaded.
I am assuming the URL format can be wrong I tried even hard code a PDF URL like:
NSString *stringURL = #"itms-books://linktopdf.pdf";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
But the same result.
2) Button tapped action:
NSURL *fileURL = document.fileURL;
NSString *fileName = document.fileName; // Document
UIDocumentInteractionController *docController = [[UIDocumentInteractionController alloc] init];
docController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
docController.delegate = self;
But I have an warning where I try to delegate: docController.delegate = self;
assigning to id UIDocumentInteractionControllerDelegate from Incompatible ReaderViewController
Can someone help me to make it work at least 1 of these solution.

Has the ReaderViewController this kind of line in the header file: #interface ReaderViewController : NSObject < UIDocumentInteractionControllerDelegate > ?

Your class must conform to the UIDocumentInteractionControllerDelegate protocol, so in your .h file make it look like
#interface ReaderViewController : PerantClass <UIDocumentInteractionControllerDelegate>
{
...
}
Then the compiler will know that your class conforms to that protocol. Of course, you still need to implement the needed methods.
ALso Check this Link - 1 And Link - 2.

Related

QLPreviewController not working in iOS 6

In iOS 6 the QLPreviewController no longer loads a PDF from a URL. It works fine in iOS 5. I have implemented the QLPreviewControllerDataSource methods as documented here.
#pragma mark - QLPreviewControllerDataSource
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
return 1;
}
- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index;
{
NSURL *fileURL = [NSURL URLWithString:#"http://www.bliley.net/XTAL/PDF_Instructions/Test_File.pdf"];
return fileURL;
}
This works perfectly in iOS 5, however in iOS 6 the console outputs:
Couldn't issue file extension for path: /XTAL/PDF_Instructions/Test_File.pdf
Have you tried using fileURLWithPath instead of URLWithString? I had other issues that were fixed by doing so.
Also not sure if QLPreviewController will handle remote URLs. If not, you could download the file and then display it.
I downloaded the file from remote url and saved locally, then I display the PDF using the QLPreviewController .In iOS 6 its working.
First i saved the file from remote url using the following code :
NSString *local_location;
NSString *path = [[NSBundle mainBundle] pathForResource:#"sampleData" ofType:#"plist"];
path = NSTemporaryDirectory();
local_location= [path stringByAppendingPathComponent:[NSString stringWithFormat:#"My_Invoice.pdf"]];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString: remoteurl]];
[request setDownloadDestinationPath:local_location];
[request startSynchronous];
For showing the Pdf :
QLPreviewController* preview = [[QLPreviewController alloc] init];
preview.dataSource = self;
[self presentModalViewController:preview animated:YES];
QLPreviewController delegate methods are :
- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
{
return 1;
}
- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
return [NSURL fileURLWithPath:local_location];
}
I am having a similar issue and seems like it might stem from a stricter enforcement of the file-type URL of QLPreviewItem
#property (readonly) NSURL *previewItemURL;
Discussion
This property is used by a Quick Look preview controller to get an item’s URL. In typical use, you would implement a getter method in your preview item class to provide this value.
The value of this property must be a file-type URL.
If the item is not available for preview, this property’s getter method should return nil. In this case, the Quick Look preview controller displays a “loading” view.
Availability
Available in iOS 4.0 and later.
Declared In
QLPreviewItem.h
UPDATE: I have opened a bug with Apple dealing with this issue for iOS 6 and it seems they have aced it as a bug so may offer a fix in the near future. The bug I opened had to do with using custom NSURLProtocols for the preview, but may apply to other aspects as well.
Link to class
But note that QLPreviewController expects a URL to a local resource
You would need to download and save the PDF file locally first and then create a proper file URL to the local file.

Adding QLPreviewController as subview doesn't load PDF

I'm trying to add a QLPreviewController's view as a subview (no--I cannot use a nav controller or modal). It only shows the fabric background of the QLPreviewController.
I create one and add it as a subview:
QLPreviewController* preview = [[[QLPreviewController alloc] init] autorelease];
preview.dataSource = self;
preview.delegate = self;
preview.view.frame = CGRectMake(0, 0, self.pdfPreviewView.frame.size.width, self.pdfPreviewView.frame.size.height);
self.pdfPreviewView.previewController = preview;
[self.pdfPreviewView addSubview:preview.view];
[preview reloadData];
My QLPreviewControllerDataSource methods work fine (viewing 1 pdf at a time):
- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index
{
NSString *path = [[ResourceManager defaultManager] pathForPDF:self.currentPDF];
NSURL *url = [NSURL fileURLWithPath:path];
if ([QLPreviewController canPreviewItem:url]) {
return url; // This always returns
}
return nil; // This line is never executed
}
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
return 1;
}
The data source method always returns the file url, and QLPreviewController says it can open the file, but it never actually does. I just get the background. The self.currentPDF is set before I create the QLPreviewController and does contain the correct information (from CoreData).
The delegate methods never get called. But I'm also not using it in a standard way, so that's not totally unexpected.
I've also tried calling [preview setNeedsLayout], [preview setNeedsDisplay'], and [preview refreshCurrentPreviewItem] but those just call the data source methods and don't change anything.
The PDFs are valid. I can open them in both Xcode and Preview, so that's not the problem. I'm kind of stumped as to why this won't work. Any help would be appreciated in getting this to work.
Turns out I was sending QLPreviewController the wrong path. It wasn't finding the PDF in the bundle correctly. I needed to use pathForResource:ofType:inDirectory.

"Root" key from plist is not recognized from the AppDelegate?

i have a simple question : why does "origineArray" return (null) ? i found out that if i put all the code in the RootViewController it works, but if i put it in the AppDelegate (as it is in a sample code, i don't which way is better?) , it does not recognize the "Root" key :
- (id)init {
self = [super init];
if (self){
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:#"origine.plist"];
origine = [[NSDictionary dictionaryWithContentsOfFile:finalPath]retain];
}
return self;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(#"origine data : %#", origine);
NSArray *origineArray = [origine objectForKey:#"Root"];
NSLog(#"origineArray data : %#", origineArray);
Thanks for your help
If your application delegate is created in a nib file, the init method is not called. Items in nibs are archived already initialized.
If you want initialization of an object loaded from a NIB, implement the - (void) awakeFromNib method.
You are logging the "origine" dictionary, what does it log to the console? If the "Root" key is not there then you are not opening the right file obviously. If the dictionary is NULL then you need to fix the path.
Are you sure that finalPath contains the right path? It seems that the origin.plist is in the resources folder but you are using the location of your app bundle in the finder.

webview in iphone

I m passing an url as string from UIviewController to another uiviewcontroller..i was able to pass the url successfully but not able to load the string in the webview...in console i m getting a null value in webview could u guys help me out below is the code...
-(void)playAction1
{
webviewcontroller *newEnterNameController = [[webviewcontroller alloc] initWithItem:#"http://www.theappcodeblog.com/?p=222"];
[self.navigationController pushViewController:newEnterNameController animated:YES];
[newEnterNameController release];
}
- (id)initWithItem:(NSString *)url
{
if (self = [super initWithNibName:#"webviewcontroller" bundle:nil])
{
self.title=#"facebook";
self.url1 = [NSURL URLWithString:url];
//URL Requst Object
self.requestObj1 = [NSURLRequest requestWithURL:url1];
NSURLConnection *connection=[[[NSURLConnection alloc] initWithRequest:self.requestObj1 delegate:self]autorelease];
[self.webViewAnnouncements loadRequest:self.requestObj1];
NSLog(#"webView:%#",webViewAnnouncements);
[self.webViewAnnouncements setDelegate:self];
}
return self;
}
While what you're doing doesn't look wrong to me (in truth I'd need to see .h and .xib files) as well to be sure. I would consider the initWithItem to be an unusual pattern.
If I was you, I would init the view controller in the "normal" way using initWithNib and then create the URL as a property type and set it before you present the view controller to the screen.

Objective-C 'RootViewController' may not respond to '-parseXMLFileAtURL:' error in xCode

I have this error when building and running my project in xCode:
RootViewController may not respond to -parseXMLFileAtURL:
I'm attempting to develop the basic Apple RSS Reader from the tutorial at:
http://gigaom.com/apple/tutorial-build-a-simple-rss-reader-for-iphone/
my section of code that this error is occurring in looks like this:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if ([stories count] == 0)
{
NSString * path = #"http://feeds.feedburner.com/TheAppleBlog";
[self parseXMLFileAtURL:path];
}
cellSize = CGSizeMake([newsTable bounds].size.width, 60);
}
can anybody explain why this parseXMLFileAtURL command gives so much heartache?
Thanks
UPDATED***
I also define parseXMLFileAtURL in the same file; however, I placed that section of the code after the viewDidAppear method (my bad). So when I change the order of the methods that error goes away. But when I do that, I get another error, maybe you guys can help with that error too! here it is:
Class RootViewController does not implement the NSXMLParserDelegate protocol
within this section of code:
- (void)parseXMLFileAtURL:(NSString *)URL
{
stories = [[NSMutableArray alloc] init];
NSURL *xmlURL = [NSURL URLWithString:URL];
rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[rssParser setDelegate:self];
[rssParser setShouldProcessNamespaces:NO];
[rssParser setShouldReportNamespacePrefixes:NO];
[rssParser setShouldResolveExternalEntities:NO];
[rssParser parse];
}
The error occurs after the line: [rssParser setDelegate:self]; - what might be wrong with that?
In regards to your second question that RootViewController does not conform to the NSXMLParserDelegate protocol. Just add it like this in your RootViewController.h file:
#interface RootViewController : UIViewController <NSXMLParserDelegate> { .....
Silly question: Does your RootViewcontroller class have a method named -parseXMLFileAtURL: defined? If -parseXMLFileAtURL: comes after the method that calls it, you'll also need to declare it in your header.
Make sure you have parseXMLFileAtURL defined in your RootViewController.m
-(void)parseXMLFileAtURL:(NSString *)url
{
...
}
And make sure you have it defined in your header as:
-(void)parseXMLFileAtURL:(NSString *)url;
Also, make sure that when you try to get the contents from the web, you're using an NSURL, not an NSString. You can instantiate a NSURL with a string by:
NSURL *urlFromString = [[NSURL alloc] initWithString:#"http://..."];