1.I am working on UIWebView and I wanna to ask how do set up hidden button on the UIWebView or navigation bar (with buttons on) I want to implement tap screen to show those buttons.
Can anyone give me some suggestions?
2.I am using http get to get image from such address:10.103.198.246:85/snapshot.cgi (api only support get method)
how do I display that image using returning data?
NSURL *url1 =[NSURL URLWithString:#"http://#10.103.198.246:85/snapshot.cgi"];
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url1 cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10];
NSData *received = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *str = [[NSString alloc]initWithData:received encoding:NSUTF8StringEncoding];
NSLog(#"%#",str);
This how I get text info. but how do i display image data?
Thanks!
Add a Tap gesture recognizer to the UIWebView. On the tap event, add a semi-transparent view to the WebView and add the buttons you need to that new view.
UIImage has an -initWithData: method that you can use to get the UIImage object. Not sure in a .cgi extension is supported, might only by common formats like .jpg or .png
UIImage *img = [[UIImage alloc]initWithData:received.....];
Related
I am using UIWebview to load a weburl, which contains few images and text. But after loading the url on webview images gets replaced with one another on some devices.
Is it problem with webpage?
My Code is here
NSURL *url=[[NSURL alloc]initWithString:_url];
NSURLRequest *request=[NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
I have attach link to the actual loaded webview.
this image actually appears to some other location but right now it gets loaded to this place
Try to this one , it may help you..!!
https://github.com/AdrianFlorian/AFImageViewer
Images url are old, please replace with other like:
#image url: http://www.citi.io/wp-content/uploads/2015/10/1291-01-bruges-meteoweb.eu_.jpg
-(NSArray *)imageUrls
{
return [NSArray arrayWithObjects:
[NSURL URLWithString:#"http://imgs.mi9.com/uploads/landscape/4717/free-the-seaside-landscape-of-maldives-wallpaper_422_84903.jpg"],
[NSURL URLWithString:#"http://pics4.city-data.com/cpicc/cfiles42848.jpg"],
nil];
}
In my ios application, I am displaying a *.svg file as below:
NSString *path = [[NSBundle mainBundle] pathForResource:#"myFile" ofType:#"svg"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:path];
NSURLRequest *req = [NSURLRequest requestWithURL:fileURL];
[_webView setScalesPageToFit:YES];
[_webView loadRequest:req];
This works fine as I can load pinch and zoom the file on device. But now I need to highlight and area of image (say a room of a building or well of a garden). How can I achieve this? I have tried SVG Kit, but I was not able to find the touch-highlight area property. I've also used FSInteractiveMapView. But is does not allow me to pinch and zoom or scrol through the svg image. Please help me.
I need help, I have an application that collects my profile picture facebook, the problem is that if I change this profile picture on facebook and then go to my application, I still shows the old image, but the service returns me good url with the updated image, which can be happening?
if ([session sessionType] == MASTFacebook) {
NSLog (# "fbPictureURL:% #", [(MAFacebookSession *) session fbPictureURL]);
[self.userImgView setImageWithURL [(MAFacebookSession *) session fbPictureURL]];
}
Because you are caching image, try to use NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:-1]; and use method like setImageWithURLRequest to set your UIImageView.
In your case, the code should be like followings if you are using UIImageView+AFNetworking
if ([session sessionType] == MASTFacebook) {
NSLog (# "fbPictureURL:% #", [(MAFacebookSession *) session fbPictureURL]);
NSURL *url = [(MAFacebookSession *) session fbPictureURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:-1];
// if you are using UIImageView+AFNetworking. the method is as follows
[self.userImgView setImageWithURLRequest:request placeholderImage:nil success:nil failure:nil]];
}
Because you are using setImageWithURL so it will cache your image automatically by url , so you should also update image url after update image.
best way will be once you get the image url from Facebook convert it into UIImage and save it. depending on your requirement(app delegate , UserDefaults). Then assign it to ImageView. So that you can use image in any view controller as the your profile pic is already convert into Image it will not take time to convert(not caching but works as cache). when ever you login you can get the updated profile pic.
ex:
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
[defaults setObject:[NSData dataWithContentsOfURL:[NSURL URLWithString:#"your image url" forKey:#"profileImage"];
Here you can saving Data (In UserDefaults we can not save image so we save data).
UIImageView *view =[[UIImageView alloc]initWithData:[defaults objectForKey:#"profileImage"]];
I am developing a simple testing app for iPhone. I want to click a button to change the URL of webview, then load the new URL. Here is my code:
NSString *nurl = [NSString stringWithFormat: #"http://www.abc.com/abc.aspx?SN=%#&fdate=%#&tdate=%#", SNstr, fDate, tDate];
NSLog(#"################: %#", nurl);
NSURL *url = [NSURL URLWithString:nurl];
NSLog(#"################: %#", url);
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[Logs loadRequest:req];
It is working well inside viewDidLoad.
I move it into a button:
-(IBAction)CheckLog:(id)sender
{
// codes here
}
When I press the button, it gives nurl's value correct, but url's value is null. So nothing is changed on the UIWebView Logs.
Why could this be, when the code runs correctly in viewDidLoad?
your button action will be like this...
-(IBAction)CheckLog:(id)sender
{
[[NSURLCache sharedURLCache] removeAllCachedResponses];
NSString *nurl = [NSString stringWithFormat: #"http://www.abc.com/abc.aspx?SN=%#&fdate=%#&tdate=%#", SNstr, fDate, tDate];
NSURL *url = [NSURL URLWithString: [nurl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ];
// NSURL *theURL = [NSURL URLWithString:#"https://www.google.co.in/"]; // Your new URL
[self.myWebView loadRequest:[NSURLRequest requestWithURL:url]];
}
The first thing to check is that the method is definitely being called. Are your NSLog statements being printed? If not, check that you have connected the button to the IBAction correctly in Interface Builder.
I can't see anything in your code that is immediately jumping out to me as incorrect, so your best bet is to set a breakpoint at the start of the method and step through it line-by-line, checking the values of each variable as you go.
I am pulling a text from a plist and draw it into a UIView.
The text contains terms that I want to be highlighted and user interaction enabled so I could pop a dictionary view with the teem explanation.
I know how to find their location on the string and that works fine.
But I did not find how to make them a appear in different color.
And even more important to me - how to add a tap recognizer to them.
I would appreciate any help.
Thanks
Shani
Add a transparent button with the same font and text in front of where the word appears in the UIView. I have a class that will do this with a UILabel if you'd like it? It creates the same effect as with the Facebook application.
O.k
i found a solution that works great for me.
i am using UIWebView as The view for the text and then adds the text formatted as HTML.
in this way i can use CSS to format the text better and even tag some of the text as link ,in the example i want that the word consonant will appear as a link.
(an other great benefit is that I can add support to RTL languishes).
UIWebView *webView =[[UIWebView alloc] initWithFrame:imgViewRect];
webView.backgroundColor = [UIColor clearColor];
webView.opaque=NO;
webView.delegate=self;
NSString *localizedPath = [NSString stringWithFormat:#"rt%#",pcard.card_number];
NSString *localizedString = NSLocalizedString(localizedPath,#"");
NSString *cssPath = [[NSBundle mainBundle] pathForResource:#"style" ofType:#"css"];
//do base url for css
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
NSString *html =[NSString stringWithFormat:#"<dfn>consonant</dfn>",
currentLanguage,dir,cssPath,langClass,localizedString];
NSLog(#"%#",html);
[webView loadHTMLString:html baseURL:baseURL];
[self addSubview:webView];
then i use this function to recognize what word clicks and lunch a UIView with the dictionary text:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request
navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
NSURL *URL = [request URL];
NSLog(#"%#",[URL lastPathComponent]); //thats gives me the name of the clicked word.
//here you can set any function that you like.
//using the data from the url path.
}
return YES;
}
hope it will help someone.
shani