Override tap gesture in tttaributredlabel link - objective-c

In my application , I have a tttattributedlabel detect link and open in web view . if I set uitapgesture on this attributed label then gesture is always fire .
link is not working in any case if tap gesture set on attributed label .

You can try with it.
NSString *pathStr=#"http://stackoverflow.com/questions/29427320/override-tap-gesture-in-tttaributredlabel-link?noredirect=1#comment47025717_29427320";
if ([pathStr hasPrefix:#"http"]) {
UIWebView *myWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
myWebView.autoresizesSubviews = YES;
myWebView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
NSURL *myUrl = [NSURL URLWithString:pathStr];
NSMutableURLRequest *myRequest = [NSMutableURLRequest requestWithURL:myUrl];
[myWebView loadRequest:myRequest];
myWebView.delegate=self;
[self.view addSubview: myWebView];
}

Related

HTTP load failed and I have tried all of the SO suggestions, but nothing works

Error 9802 is a "Fatal Alert" according to the Apple's docs. I have looked at Google and SO and found nothing referencing 9802 that fixes this problem. I can change my code to go for "apple.com" and I get the page, but using my own URL, I get the error above. I have tried everything that I can think of, and nothing works. Time to ask for help! :D
The result of using
/usr/bin/nscurl --ats-diagnostics https://pragerphoneapps.com
is all tests fail (results are uploaded here)
This is an image of my app's .plist file (only pertinent part)
and this is an image of the target info:
And this is my code:
- (IBAction)showHTMLHelp:(UIButton *)sender {
// make the popover
UIViewController* popoverContent = [UIViewController new];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 450, 500)];
popoverView.backgroundColor = [UIColor colorWithWhite:(CGFloat)1.0 alpha:(CGFloat)1.0]; // frame color?
popoverContent.view = popoverView;
//resize the popover view shown in the current view to the view's size
popoverContent.preferredContentSize = CGSizeMake(450, 500);
NSString *urlAddress = #"https://pragerphoneapps.com"; // #"https://www.pragerphoneapps.com/bookstore-inventory-manager/upload-help/";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
// add the UIWebView for RichText
UIWebView *webView = [[UIWebView alloc] initWithFrame: popoverView.frame];
webView.backgroundColor = [UIColor whiteColor]; // change background color here
// add the webView to the popover
[webView loadRequest:requestObj];
[popoverView addSubview:webView];
// if previous popoverController is still visible... dismiss it
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
}
//create a popover controller
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[popoverController presentPopoverFromRect:((UIButton *)oShowHelp).frame inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
I seriously recommend you to fix your SSL certificate.
ATS requires you to have a valid SSL certificate, TLS version 1.2 or above and support for forward secrecy.
This will be a requirement at the beginning of 2017 so better get ready.
Anyway, meanwhile try the following steps to get this working.
Put this on top of your file:
#interface NSURLRequest (InvalidSSLCertificate)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host;
+ (void)setAllowsAnyHTTPSCertificate:(BOOL)allow forHost:(NSString*)host;
#end
Disable App Transport Security in Info.plist.
Allow invalid SSL certificates before loading request:
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
Sample code that successfully loads your site:
NSString *urlAddress = #"https://pragerphoneapps.com"; // #"https://www.pragerphoneapps.com/bookstore-inventory-manager/upload-help/";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
UIWebView *webView = [[UIWebView alloc] initWithFrame: self.view.frame];
webView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:webView];
[webView loadRequest:requestObj];
I wonder why it can't work for setting "NSAllowArbitraryLoads to YES".If there are caches, try to reboot your Mac or Xcode.
And your "Exception Domains" settings have the wrong format.

UIWebView sharp corners

I have an UIWebView with and using QuartzCore to add some style to this. But when i'm execute:
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, self.view.bounds.size.width-20.0, self.view.bounds.size.height-30.0)];
NSString *urlAddress = #"http://www.google.com/";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
webView.layer.cornerRadius = 10;
webView.layer.borderColor = [UIColor whiteColor].CGColor;
webView.layer.borderWidth = 3.0f;
[self.view addSubview:webView];
I get an rounder View but content is sharp. There is a way to roundend corners in content in WebView
The content view is actually the scrollView of UIWebView, so
webView.scrollView.layer.cornerRadius = 10;
Agreed with #graver Answer but not completely Coz His working will not work on iphone 3g and iPod 2nd generation .
webView.layer.cornerRadius = 10;
[webView setClipsToBounds:YES];
ClipsToBound will simple resize all the subviews under webView.

How to tell when UIWebView has finished displaying content

I'm making a UIWebView load a pdf like this:
UIWebView *pdfView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]];
pdfView.delegate = self;
[pdfView loadRequest:request];
And then doing some stuff with the view once it loads:
- (void)webViewDidFinishLoad:(UIWebView*)sender {
[sender takeScreenshot]; // my UIView category screenshot method
[sender release];
}
It all works, apart from the fact that at the point webViewDidFinishLoad is called, the view hasn't displayed anything yet, it displays a few milliseconds later. So is there any way to tell when the UIWebView has finished displaying its content (a pdf in this case)?
You could do:
[self performselector:#selector(getScreenshot) withObject:sender afterDelay:0.1];
-(void) getScreenshot:(UIWebView *)webView {
[webView takeScreenshot];
[webView release];
}
Or something similar.

How to zoom webView with pdf file

How to get zoom in UIWebView.
I loaded pdf file from resource bundle in a UIWebView.
Now trying to zoom the webview. so its will get zooming effect to the pdf file.
So.
How can i zoom the UIWebView.
Any sample example. Please help me out.
Just use the following code:
self.pdfviewwebview.scalesPageToFit = YES;
self.pdfviewwebview.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.pdfviewwebview.delegate = self;
The most tricky thing here which most people forget is to set the webview's delegate,so take care about that.
UIWebView *tempWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height)];
tempWebView.backgroundColor = [UIColor whiteColor];
**tempWebView.scalesPageToFit = YES; //this enables the zooming**
tempWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
tempWebView.delegate = self;
[self.view addSubview:tempWebView];
[self setWebView:tempWebView];
NSString *path = [[NSBundle mainBundle] pathForResource:#"your_file" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[self.webView loadRequest:request];
A pinch-to-zoom gesture can be simulated by holding down the Option key. On your simulator, two grey circles will appear indicating that its simulating a multi-touch, pinch-to-zoom gesture.

Hide button on first of two UIViews, but have it visible on second

So I have a UIViewController (main application controller is a TabBarController). On this there is a UINavigationBar, and a UIBarButtonItem. I'm PRETTY sure I hooked up everything correctly in the Interface Builder and that the outlet in the code is connected to the button in the .xib. It should be because the method works correctly.
Now I have another button on this view that brings up a second view, a UIWebView. I want this UIBarButtonItem, labeled "Back", to make the UIWebView dissapear, and bring back the first UIView, which it DOES DO correctly. However, when you are on the first UIView, there is no need to see the UIBarButtonItem, so how can I hide it but then bring it up for the UIWebView. By the way, both views use the same UINavigationBar, the UIWebView is brought up inside the tab bar and the nav bar.
Here is my code:
#import "WebViewController.h"
#implementation WebViewController
#synthesize webButton;
#synthesize item;
#synthesize infoView;
UIWebView *webView;
+ (UIColor*)myColor1 {
return [UIColor colorWithRed:0.0f/255.0f green:76.0f/255.0f blue:29.0f/255.0f alpha:1.0f];
}
// Creates Nav Bar with default Green at top of screen with given String as title
+ (UINavigationBar*)myNavBar1: (NSString*)input {
UIView *test = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, test.bounds.size.width, 45)];
navBar.tintColor = [WebViewController myColor1];
UINavigationItem *navItem;
navItem = [UINavigationItem alloc];
navItem.title = input;
[navBar pushNavigationItem:navItem animated:false];
return navBar;
}
- (IBAction) pushWebButton {
self.navigationItem.rightBarButtonItem = item;
CGRect webFrame = CGRectMake(0.0, 45.0, 320.0, 365.0);
webView = [[UIWebView alloc] initWithFrame:webFrame];
[webView setBackgroundColor:[UIColor whiteColor]];
NSString *urlAddress = #"http://www.independencenavigator.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
webView.scalesPageToFit = YES;
[webView loadRequest:requestObj];
[self.view addSubview:webView];
[webView release];
}
- (void) pushBackButton {
[webView removeFromSuperview];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
self.navigationItem.rightBarButtonItem = nil;
[super viewDidLoad];
}
#end
Anyone know?
Edit: This answer does not work with nil, but I'm leaving it here as it does work when you want to temporarily replace the back button with another button. See correct answer below in comments.
You might try something like this:
In an App I'm working on there are cases where I'd like to temporarily swap the back button for a cancel button,
so I save a pointer to it:
tempButtonItem = self.navigationItem.leftBarButtonItem;
change the navigationItem.leftBarButtonItem to a cancel button:
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self
action:#selector(cancelButtonPressed)]
autorelease];
And then later when I want to have the back button again I restore it:
self.navigationItem.leftBarButtonItem = self.tempButtonItem;