I am creating a webview and loading content using "loadHTMLString" The content is loading I just can't get the links to work ex linking to google.com. Any help would be great.
UIWebView* newWeb = [[UIWebView alloc initWithFrame:CGRectMake(notificationPopUp.frame.origin.x+ 20,notificationPopUp.frame.origin.y-100,100, 100)];
//newWeb.backgroundColor = [UIColor clearColor];
newWeb.alpha = 0.7;
newWeb.opaque= NO;
newWeb.delegate= self;
NSString *html = [NSString stringWithFormat:#"<html><head><title></title><style type=\"text/css\">a{text-decoration:none}</style></head><body><FONT COLOR=\"#484848\"><p>Hello this is a Test</p></FONT></body></html>"];
[newWeb loadHTMLString:html baseURL:[NSURL URLWithString:#""]];
newWeb.userInteractionEnabled= TRUE;
[notificationPopUp addSubview:newWeb];
I added this code to an empty project and links are clickable. The only thing I can think of is your notificationPopUp view is somehow preventing taps from going to the webview.
Related
We've the following method to share content in the application. For each content we share:
Text
Image
URL
+ (void) generalShare:(NSString *) text withEntity:(SMEntity *) theEntity onView:(UIViewController*) theViewController withImage:(UIImage *) image completion:(void (^)(void))completion
{
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:templateURL
, [SMSocialManager getAction:theEntity]
, [theEntity getId]]];
NSArray *sharingItems = #[text, url, image];
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];
[activityController setValue:text forKey:#"subject"];
[UINavigationBar appearance].barStyle = UIBarStyleBlack;
[UINavigationBar appearance].translucent = NO;
[UINavigationBar appearance].barTintColor = UIColorFromRGB(SMPrimaryColor);
[theViewController presentViewController:activityController animated:YES completion:^{
return completion();
}];
}
Until a few time it works perfectly, a few time ago the text was missing when you try to share in facebook (based on the new policy) but just a days ago the image, is also missing, and just the URL is included.
Any suggestions?
I could figure out generating an ad-hoc solution for each destination social network, but find a way to solve with an standard solution could be better approach.
Thank you!
It seams facebook and instagram removed the caption from the integration, and I don't know why but with facebook also the image is not working anymore.
Using this code to play YouTube video in UIWebView
- (void)embedYouTube {
UIWebView *webView = [[[UIWebView alloc] initWithFrame:self.view.bounds] autorelease];
webView.autoresizesSubviews = YES;
webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
// iframe
videoHTML = [NSString stringWithFormat:#"\
<html>\
<head>\
<style type=\"text/css\">\
iframe {position:absolute; top:50%%; margin-top:-130px;}\
body {background-color:#000; margin:0;}\
</style>\
</head>\
<body>\
<iframe width=\"560%%\" height=\"315px\" src=\"%#\"http://www.youtube.com/embed/j9CukQje2qw\" frameborder=\"0\" allowfullscreen></iframe>\
</body>\
</html>", videoURL];
[videoView loadHTMLString:videoHTML baseURL:nil];
}
When i click on this LaunchVideo UIButton all it shows black screen on iOS device
-(void)LaunchVideo:(id)sender
{
self.videoURL = #"http://www.youtube.com/embed/j9CukQje2qw";
WebViewController *webViewController = [[[WebViewController alloc] initWithNibName:nil bundle:nil] autorelease];
webViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
webViewController.videoURL = self.videoURL;
[self presentModalViewController:webViewController animated:YES];
}
If anyone can point out what i m missing or doing wrong in this code. Why youtube video is not showing. Not using interface builder doing programmtically. Got this project code from web. Tried this project code on ios device it works fine for that project but when applied its code in my project then it is not working. Only difference that his projectcode from web uses interface builder and i am doing it programmtically.I dont get it.
Please help what is wrong with this code.
Thanks for help.
Here is another way to load the youtube video into your app. First, put a UIWebView into your interface and size it to how big you want the video should show (there will be a button to make it full screen), then make an IBOutlet to it, so you can change its properties of hidden (to make it pop up and go away) Here is some code. In the code there is a method used called webviewshow, this calls a simple method that basically just says
webview.hidden = NO;
webviewbutton.hidden = NO;
Then there is a button that also pops up that makes the web view go away when tapped. Here is the code to load the youtube video into the web view
// Create your query ...
NSString* searchQuery = [NSString stringWithFormat:#"http://www.youtube.com/embed/j9CukQje2qw];
// Be careful to always URL encode things like spaces and other symbols that aren't URL friendly
searchQuery = [searchQuery stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
// Now create the URL string ...
NSString* urlString = searchQuery;
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
[webView loadRequest:request]; currentTimer= [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:#selector(webviewshow) userInfo:nil repeats:NO];;
It waits 2 seconds (usual wait time for most connections) until the web view is shown, so the page is loaded and the user does not have to watch it load.
Then when you want to make the video go away, make a method to close the web view like so
- (void) makewebviewGoAway {webview.hidden = YES; webviewbutton.hidden = YES;}
Hopefully, that was helpful. IF you need further help or explanation, just comment off of this.
Facebook comment part of webview keep loading and it never finish on device.
But, it works just fine on simulator.
Does somebody have an idea to fix this? Thanks in advance!
This is the code to add UIWebview on UIViewController.
NSString *address = #"http://techcrunch.com/2012/03/10/entrepreneurs-are-difficult-at-best-and-abrasive-at-worst-get-over-it/?grcc=33333Z98";
//make webview frame
webView_ = [[UIWebView alloc] init];
webView_.delegate = self;
webView_.frame = self.view.bounds;
webView_.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
webView_.scalesPageToFit = YES;
[self.view addSubview:webView_];
//load page on webview
NSURL *myURL = [NSURL URLWithString:address];
NSURLRequest *myURLReq = [NSURLRequest requestWithURL:myURL];
[webView_ loadRequest:myURLReq];
This is the error message on - (void)webView:(UIWebView *)webView didFailLoadWithError:
Error Domain=NSURLErrorDomain Code=-999 "The operation couldn't be completed. (NSURLErrorDomain error -999.)"
Update
I tested it with a clean uiwebview, since the previous build had Sharekit plugin,
but the error still exist with a new build. Also, this link is related,
First dialog after authenticating fails immediately and closes dialog
FYI, I opened a bug recently on this. Facebook hasn't really responded and oddly classified it as a "wishlist" item:
https://developers.facebook.com/bugs/373249496041875?browse=search_4fa8cf425c5aa8d66140047
I have successfully embedded a vimeo video using a UIWebView. However because i have created this in code, i have to adjust the positioning in code and i would prefer to do it through interface builder. Correct me if im wrong, i read that initializing UIWebView with the initWithCoder method was the way to achieve this. However i am not to sure how to properly make use of this method, if it is at all the right one.
Here is a bit code to show what i have been doing so far:
- (void) viewDidLoad{
[super viewDidLoad];
[self embedVimeo:#"http://player.vimeo.com/video/19969613" frame:CGRectMake(300, 100, 260, 200)];
[self embedVimeo:#"http://player.vimeo.com/video/19967404" frame:CGRectMake(100, 300, 260, 200)];}
- (void)embedVimeo:(NSString *)urlString frame:(CGRect)frame {
NSString *embedHTML = #"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body style=\"margin:0\">\
<iframe src=\"%#\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></iframe>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];
/*UIWebView **/ videoView = [[UIWebView alloc] initWithFrame:frame];
[videoView loadHTMLString:html baseURL:nil];
[[[videoView subviews] lastObject] setScrollEnabled:NO];
[mainView addSubview:videoView];
[videoView release];
}
Any ideas?
Tod
It is my understanding that the initWithCoder is automatically used by the Objective-C runtime/Cocoa/CocoaTouch to accomplish what you are aiming at. So you don't have to really worry about it.
In short, if you create you UI in IB, say instantiate there a UIWebView object, define its connection a controller of yours, then you will be able to use that UIWebView directly without worrying about having to instantiate it.
What I would do is:
creating a new Web View in my nib;
a controller/delegate for the WebView;
connect the WebView delegate to the controller/delegate;
connect the controller/delegate view to the WebView;
connect the rootViewController of the main window to the controller/delegate.
Once you make sure you have defined correctly all the outlets and connection, my simply loading this nib (which in case it is the MainMenu is done automatically), you'll have all of those objects instantiated and ready to be used (by calling loadHTMLString: or whatever.
Hope this helps.
Am trying to load a .docx file into the uiwebview and am displaying it.To load the document into the webview it takes some fraction of seconds so i can see a white blank screen before the content can appear on the screen.I don't want to see that white screen while loading instead of that i want to do some actions like activity indicator or changing the background.How can i achieve this please help me.
Here is my code;
-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webViews
{
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 416)];
isWebviewLoaded=YES;
webView.delegate=self;
webView.alpha=0;
NSString *path = [[NSBundle mainBundle] pathForResource:#"SKIN ADVISORuser_updated.docx" ofType:nil];
//NSString *path = [[NSBundle mainBundle]pathForResource:#"UserGuidelines3.html" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webViews loadRequest:request];
}
and in viewdidload am calling above method:
[self loadDocument:#"ADVISORuser_updated.docx" inView:self.webView];
Even am implementing a delegate method to change the background but delegate is not executing
- (void)webViewDidFinishLoad:(UIWebView *)webViewload {
if (isWebviewLoaded)
{
isWebviewLoaded = NO;
webView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:#"Instructions Screen Background light_PNG.png"]];
[UIView beginAnimations:#"webView" context:nil];
webView.alpha = 1.0;
[UIView commitAnimations];
}
}
Please can anyone help me..
before loadRequest u could create UIActivityIndicator object and start it by calling start method
and in webView delegate didFinishLoading: & didFailwithError method suspend the activity indicator
- (void)webViewDidFinishLoad:(UIWebView *)webViewload {
will be called only if you have set the delegate for the webView (in the xib &.h file)