PDFs not showing, Other URLs do - iphone

I am having difficulty with a UIWebView which shows http URLs correctly, but not bundled .pdf files.
I have also read alternative solutions such as using QuartzCore framework, however this does not seem to support multiple pages in PDFs.
Here is the code that works (for google dot com)
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *pdfPath = [[NSBundle mainBundle] pathForResource:#"file" ofType:#".pdf"];
NSURL *pdfURL = [NSURL URLWithString:pdfPath];
CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
webFrame.origin.y += kTopMargin - 20.0; // leave from the URL input field and its label
webFrame.size.height -= 00.0;
self.webView = [[[UIWebView alloc] initWithFrame:webFrame] autorelease];
self.webView.backgroundColor = [UIColor whiteColor];
self.webView.scalesPageToFit = YES;
self.webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.webView.delegate = self;
[self.view addSubview: self.webView];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.google.com"]]];
}
And for the PDF, I have replaced
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.google.com"]]];
with
[self.webView loadRequest:[NSURLRequest requestWithURL:pdfURL]];
My immediate thought was that the iPhone SDK does not support PDF viewing in its webview, however, tutorials like this one seem to show other users having success with this. So do you think I am just missing something in my code?
Thanks.

UIWebView does support pdf when using loadRequest as you are doing.
pathForResource:#"file" ofType:#".pdf"
Take the . out of .pdf
Edit:
[NSURL URLWithString:pdfPath];
Use fileURLWithPath: instead.
Check that pdfPath and pdfURL are what you expect them to be.
NSLog( #"%#" , pdfURL );

Related

Add PDF or PPT file on UIScrollview in iPhone

I am working on display PDF from resourse folder
on UIScrollview. But it is not able to add.
I add UIScrollView on ViewController. Then take a UIImageView and add on UIScrollView as bellow code.
scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0.0, 0.0,768,1024)];
scrollView.contentSize = CGSizeMake(768,2000);
scrollView.delegate = self;
scrollView.pagingEnabled = NO;
[self.view addSubview:scrollView];
UIImageView *img=[[UIImageView alloc] initWithFrame:CGRectMake(00, 20, 500,900)];
NSString *url = [[NSBundle mainBundle]pathForResource:#"Acknowledgements" ofType:#"pdf"];
img.image=[UIImage imageWithContentsOfFile:url];
[scrollView addSubview:img];
But pdf is not added on scrollview. If i add some image file like
NSString *url = [[NSBundle mainBundle]pathForResource:#"trophy" ofType:#"png"];
It get added.
PDF file is correct and open in Mac. Same case happen with PPT file.
what is going wrong.
Thanks
#interface UIWebView : UIView < NSCoding, UIScrollViewDelegate > {
UIWebView implements UIScrollViewDelegate. So you can still handle your scroll related events.
Check this link for delegate methods of UIScrollView http://developer.apple.com/library/ios/#documentation/uikit/reference/uiscrollviewdelegate_protocol/Reference/UIScrollViewDelegate.html
ppt/pdf cant be added to UIImageView, rather than add it in UIWebView
NSString *url = [[NSBundle mainBundle]pathForResource:#"Acknowledgements" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:url];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];

Foursquare integration in iPhone

I am trying to do the FourSquare integration in iPhone..i couldn't found any good guidelines through Goggling.... Can any one suggest me the Good guidelines or URLs for FourSquare integration in iPhone..
Thanks
Here is the foursquare api link
Example of Foursquare integration link.
Further code for Foursquare integration
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Foursquare";
//check the authentication
if ([Foursquare2 isNeedToAuthorize]) {
//If needed show the webview
webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
NSString *url = [NSString stringWithFormat:#"https://foursquare.com/oauth2/authenticate?display=touch&client_id=%#&response_type=code&redirect_uri=%#",OAUTH_KEY,REDIRECT_URL];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
[webView loadRequest:request];
[webView setDelegate:self];
[self.view addSubview:webView];
[webView release];
mTableView.hidden = YES;
}else{
//Show your view
mTableView.hidden = NO;
[Foursquare2 searchVenuesNearByLatitude:#"40.763" longitude:#"-73.990" accuracyLL:nil altitude:nil accuracyAlt:nil query:#"" limit:#"15" intent:#"" callback:^(BOOL success, id result){
if (success) {
tableData = [[FoursquareParser parseSearchVenuesResultsDictionary:(NSDictionary*)result] retain];
[mTableView reloadData];
}
}];
}
}

WebView seems to be leaking according to instruments. GeneralBlock-56

Instruments is reporting a lot of leaks like :
GeneralBlock-56
GeneralBlock-8192
GeneralBlock-2048
GeneralBlock-24
GeneralBlock-32
GeneralBlock-8
GeneralBlock-16
This all happens when I open a class that just displays a UIWebView.
Here is the guts of the code from the class:
appDelegate = (DemoSAPAppDelegate *)[[UIApplication sharedApplication] delegate];
UIWebView *aWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 480, 320)];
aWebView.scalesPageToFit = YES;
[aWebView setBackgroundColor:[UIColor clearColor]];
[aWebView setOpaque:NO];
NSURL *url = [NSURL URLWithString:self.urlString];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[aWebView loadRequest:requestObj];
[[[aWebView subviews] lastObject] setScrollEnabled:YES];
[self.view addSubview:aWebView];
[aWebView release];
Am I doing something wrong here? The WebView is released there at the end.
Do I need to use something like an autoreleasepool?
Quite confused to see my app hemorrhage memory over this.
Is that on an actual device? Or the simulator? The frameworks the simulator uses leaks in many places; they are not as finely tuned as the device binaries. Always test on an actual device; the simulator, is after all, just a simulation.

Trouble loading html file from plist to webView on iPhone

trouble loading html file from plist to webView using following code in
FAQDetailViewController.m:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *WebPath = [Path stringByAppendingPathComponent:WebFile];
UIWebView *tempWeb = [[UIWebView alloc] initWithContentsOfFile:WebPath];
[webView loadData:tempWeb]; //I think my issue is here. I am not understanding how to implement the the code here
[tempWeb release];
}
loaded here with this peace of code in FAQViewController.m:
FAQDetailViewController *faqdvController = [[FAQDetailViewController alloc] initWithNibName:#"FAQDetailView" bundle:[NSBundle mainBundle]];
faqdvController.WebFile = [dictionary objectForKey:#"faqDesc"]; //html file from plist file placed here
faqdvController.hidesBottomBarWhenPushed = NO;
[self.navigationController pushViewController:faqdvController animated:YES];
[faqdvController release];
You can try it this way:
NSString *bundle = [[NSBundle mainBundle] bundlePath];
NSString *webPath = [bundle stringByAppendingPathComponent:{htmlFilename}]
UIWebView* browser = [[UIWebView alloc] initWithFrame:
CGRectMake(0, 0, 200, 300)];
[browser loadRequest:[NSURLRequest requestWithURL:
[NSURL fileURLWithPath:webPath]]];
[self addSubview:browser];
You'll also want to set delegates on the browser so you get informed when the contents have finished loading.

Publish UIWebview via Facebook connect

I am using fbConnect in my Cocoa Touch application. I have UIWebview on my view, and I want to publish the UIWebview's context (its only text) to FaceBook.
How should I change the FBStream to publish my UIWebview?
FBStreamDialog* dialog2 = [[[FBStreamDialog alloc] init] autorelease];
dialog2.delegate = self;
dialog2.userMessagePrompt = #"Share Ghazals on your wall";
dialog2.attachment = #"{\"name\":\"Hafez Application for iPhone\","
"\"href\":\"http://itunes.apple.com/us/app/divan-of-hafez/id340865571?mt=8?tab=iphone\","
"\"media\":[{\"type\":\"image\","
"\"src\":\"http://photos-h.ak.fbcdn.net/photos-ak-sf2p/v43/67/279420942343/app_5_279420942343_8373.gif\","
"\"href\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}],"
"\"properties\":{\"another link\":{\"text\":\"Hafez App HomePage\",\"href\":\"http://www.momeks.com/hafez\"}}}";
// replace this with a friend's UID
// dialog.targetId = #"999999";
[dialog2 show];
Here is my UIWebView Code:
NSString *path = [[NSBundle mainBundle] pathForResource:#"webViewContent" ofType:#"html"];
NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];
NSString *htmlString = [[NSString alloc] initWithData:
[readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];
webView.opaque = NO;
webView.backgroundColor = [UIColor clearColor];
[self.webView loadHTMLString:htmlString baseURL:nil];
[htmlString release];
Not sure I understand what you mean by sharing UIWebview context.
If you want to publish text, then there are numerous examples for that on FBConnect.
You might want to try ShareKit, as it makes everything very easy....
If you could please re-explain the question, I could offer better help.
Godspeed,
Oded.