I have implemented the PinInterest through web view using this code:
NSString *description = #"Post your description here";
NSURL* sUrl = [NSString stringWithFormat:#"http://4.bp.blogspot.com/-w4oTZjlpgwo/T5_pi-KJPuI/AAAAAAAAAoM/rKm3E0XCbgY/s1600/red_rose_flower3.jpg"];// pass your link here with your image name
// NSLog(#"URL:%#", sUrl);
NSString *protectedUrl = ( NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,( CFStringRef)sUrl, NULL, (CFStringRef)#"!*'\"();:#&=+$,/?%#[]% ",CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)));
NSLog(#"Protected URL:%#", protectedUrl);
NSString *imageUrl = [NSString stringWithFormat:#"\"%#\"", sUrl];
imageUrl=[[NSBundle mainBundle]pathForResource:mAppDelegate.imagename ofType:nil];
NSString *buttonUrl = [NSString stringWithFormat:#"\"http://pinterest.com/pin/create/button/?url=www.flor.com&media=%#&description=%#\"", protectedUrl, description];
NSMutableString *htmlString = [[NSMutableString alloc] initWithCapacity:1000];
[htmlString appendFormat:#"<html> <body>"];
[htmlString appendFormat:#"<p align=\"center\"><img border=\"0\" src=\"http://assets.pinterest.com/images/PinExt.png\" title=\"Pin It\" /></p>", buttonUrl];
[htmlString appendFormat:#"<p align=\"center\"><img width=\"300px\" height = \"400px\" src=%#></img></p>", imageUrl];
[htmlString appendFormat:#"<script type=\"text/javascript\" src=\"//assets.pinterest.com/js/pinit.js\"></script>"];
[htmlString appendFormat:#"</body> </html>"];
return htmlString;
And I have also tried using PinInterest iOS SDK, but all I found is that can only pin the image from url.
And I need to pin image from local bundle image. Any help will be greatly appreciated.
Read the document once, they said Right now, "we only support pinning an image from a url. In the future, we’ll add support for pinning local images." i think this answers your question. for more clarification reed this. hope this helps :)
Related
I have created a html code like see above and the code uploaded to http://www.ged.Ic.com site.
Added an image name “1.jpg” into Xcode project.
When open iPad app loading http://www.ged.Ic.com/page/ from webview.
How to get to set image from into Xcode project to img src="image path from xcode"
NSString *imageFileName = #"image";
NSString *imageFileExtension = #"png";
NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageFileName ofType:imageFileExtension];
NSString *imgHTMLTag = [NSString stringWithFormat:#"<img src=\"file://%#\" />", imagePath];
NSString *imageUrlString = #"http://www.gstatic.com/translate/intl/ru/logo.png";
NSString *yourText = #"Some text here";
NSString *htmlString = [NSString stringWithFormat:#"<img src='%#'/><br><b>%#</b>", imageUrlString, yourText];
[myWebView loadHTMLString:htmlString baseURL:nil];
Hi in my application I'm showing the route map using google map in that its showing warning like .
stringwithcontentsofurl file deprecated in ios 2.0
The code which I'm using.
-(NSArray*) calculateRoutesFrom:(CLLocationCoordinate2D) f to: (CLLocationCoordinate2D) t {
NSString* saddr = [NSString stringWithFormat:#"%f,%f", f.latitude, f.longitude];
NSString* daddr = [NSString stringWithFormat:#"%f,%f", t.latitude, t.longitude];
NSString* apiUrlStr = [NSString stringWithFormat:#"http://maps.google.com/maps?output=dragdir&saddr=%#&daddr=%#", saddr, daddr];
NSURL* apiUrl = [NSURL URLWithString:apiUrlStr];
NSLog(#"api url: %#", apiUrl);
NSString *apiResponse = [NSString stringWithContentsOfURL:apiUrl];
NSString* encodedPoints = [apiResponse stringByMatching:#"points:\\\"([^\\\"]*)\\\"" capture:1L];
return [self decodePolyLine:[encodedPoints mutableCopy]];
}
In the above code in a particular line.
NSString *apiResponse = [NSString stringWithContentsOfURL:apiUrl];
This above line its showing warning like that please tell me how to resolve this issue.
Thanks.
As it was depreciated.You can use it as below
NSString *apiResponse = [NSString stringWithContentsOfURL: apiUrl encoding:NSUTF8StringEncoding error:nil];
The method you are using is deprecated. Use [NSString stringWithContentsOfURL: encoding: error:].
I want to get the contents of a url hosted by me. The contents of the url is
<p class="citation_style_APA">Blaine, J. D. (1992). <i>Buprenorphine: An alternative treatment for opioid dependence</i>. Rockville, MD: U.S. Dept. of Health and Human Services, Public Health Service, Alcohol, Drug Abuse, and Mental Health Administration, National Institute on Drug Abuse. </p>
Below is my code to get the above contents in a string.
NSString *s =[NSString stringWithFormat:#"%#",#"xyz.com"];
url = [NSURL URLWithString:s];
NSString *content = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:nil];
NSLog(#"%#",content);
I am getting null, can anyone tell where i am going wrong.
Try a complete web address, like #"http://www.xyz.com/myfile.html". Once you get it working, you'll want to change to an asynch technique.
You need to do two things.
1. you should use a valid url
2. NSString *content=[[NSString string] initWithContentsOfURL:url encoding:NSASCIIStringEncoding error:Nil];
Now check your Log; It'll definitely work.
Try this way
NSString *strUrl = < YOUR URL >
NSURL *url = [NSURL URLWithString:[strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSError *error = nil;
NSString *content = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:&error];
if(content==nil)
NSLog(#"%#",error!=nil ? error.description : #"");
else
NSLog(#"%#",content);
In my app, I have a view where user have to fill a form. But, sometime the app crash here, in this function, that simple cacth the value field and built a url to give
-(NSString*)urlToUpload{
NSString *string1 =[[NSString alloc]init];
string1= [NSString stringWithFormat:#"?nombre="];
NSString *string2 = [string1 stringByAppendingString:nameAdded];
//crash here
NSString *string3 = [string2 stringByAppendingString:#"&horario="];
NSString *string4 = [string3 stringByAppendingString:horarioAdded];
NSString *string5 = [string4 stringByAppendingString:#"&info="];
NSString *string6 = [string5 stringByAppendingString:infoAdded];
NSString *string7 = [string6 stringByAppendingString:#"&offerta="];
NSString *string8 = [string7 stringByAppendingString:offertaAdded];
NSString *lat_string = [[[NSString alloc] initWithFormat:#"%f",locationToUpload2.latitude] autorelease];
NSString *lon_string = [[[NSString alloc] initWithFormat:#"%f",locationToUpload2.longitude] autorelease];
NSString *string9 = [string8 stringByAppendingString:#"&latitude="];
NSString *string10 = [string9 stringByAppendingString:lat_string];
NSString *string11 = [string10 stringByAppendingString:#"&longitude="];
NSString *string12 = [string11 stringByAppendingString:lon_string];
NSString *url1 = [NSString stringWithFormat:#"http://myserverside/mysql_up.php"];
NSString *url = [url1 stringByAppendingString:string12];
return url;
}
EDIT:
It seems problem appers on nameAdded when there is a white space into textField(i.e. MisterB not crash, Mister B yes ).
But I am using:
nameAdded =[[nameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
and NSLOg give of nameAdded is Mister%20B.
The crash still appearing...
Just use a single stringWithFormat::
- (NSString *)urlToUpload {
NSString *url = [NSString stringWithFormat:#"http://myserverside/mysql_up.php?nombre=%#&horario=%#&info=%#&offerta=%#&latitude=%f&longitude=%f",
[nameAdded stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
[horarioAdded stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
[infoAdded stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
[offertaAdded stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
locationToUpload2.latitude, locationToUpload2.longitude];
return url;
}
Make sure the referenced variables are valid.
In your original code there is no need to alloc/init an NSString then assign another string to the same variable. That's a memory leak (string1).
If you really want to structure your code the way you have it, at least use an NSMutableString and append to that one mutable string. Creating over a dozen NSString variables is the wrong way to do it.
Updated: Ensure each of the strings added to the URL are properly escaped.
It looks like nameAdded may be the cause of your problems. Is it nil at that point?
Also
You are allocating a string, setting it to string1 and then immediately setting string1 to the class function stringWithFormat which allocates another string. Also you are using stringWithFormat but you aren't using any format so you could simply use NSString *string1 = #"?nombre=";
Rather than declaring all of those variables you should just use NSMutableString and build it all in one variabl
i am trying to get the path to a certain file
and then open it in a webview. so i need to replace each space by '%20'
NSString *test=#"filename";
NSString *finalPath12 = [test stringByAppendingString:#".pdf"];
NSString *path1 = [[NSBundle mainBundle] bundlePath];
NSString *finalPath1 = [path1 stringByAppendingPathComponent:finalPath12];
NSString *file =#"file://";
NSString *htmlfilename1 = [file stringByAppendingString:finalPath1];
NSString *pathtofile = [htmlfilename1 stringByReplacingOccurrencesOfString:#" " withString:#"%20"];
any string is working except #"%20".
this works perfectly for exemple:
NSString *pathtofile = [htmlfilename1 stringByReplacingOccurrencesOfString:#" " withString:#"string"];
but i need the #"%20". What am i missing ? Thanks
There is already [NSString stringByAddingPercentEscapesUsingEncoding:] (reference) for that very purpose.
However in your case, as you want a URL, you can replace all the lines in your question with:
NSURL *url = [[NSBundle mainBundle] urlForResource:#"filename" withExtension:#"pdf"];
You need to use #"%%20".
As first % is treated as escape/wild character.
Or use
stringByAddingPercentEscapesUsingEncoding: