Hi everyone I am trying to integrate pinterest into my app. I am giving the below url for image url but pinterest throwing error saying invalid image url format.
This is my image url.
http://www.healthandglow.com:8080/osafe_theme/images/catalog/products/large/503277_1.jpg
- (void)pinIt:(id)sender
{
NSURL *imageURL = [NSURL URLWithString:#"http://www.healthandglow.com:8080/osafe_theme/images/catalog/products/large/503277_1.jpg"];
NSURL *sourceURL = [NSURL URLWithString:#"http://www.healthandglow.com"];
[pinterest createPinWithImageURL:imageURL
sourceURL:sourceURL
description:#"Pinning from Pin It Demo"];
}
As it was showing invalid image url,but was working when I tried it on browser. I thought of shortening the image url and give a try and that trick worked out for me.And I am using tinyurl api which I have used in code.
Here my code goes
NSString *yourURL = [NSString stringWithFormat:#"%#%#",kBaseImageUrl,product.SKU_ImageUrls];
NSURL *sourceURL = [NSURL URLWithString:#"http://healthandglow.in"];
NSString *apiEndpoint = [NSString stringWithFormat:#"http://tinyurl.com/api-create.php?url=%#",urlstr];
NSLog(#"\n\n APIEndPoint : %#",apiEndpoint);
NSString *shortURL = [NSString stringWithContentsOfURL:[NSURL URLWithString:apiEndpoint]
encoding:NSASCIIStringEncoding
error:nil];
NSLog(#"Long: %# - Short: %#",urlstr,shortURL);
NSURL *imageURL = [NSURL URLWithString:shortURL];
[pinterest createPinWithImageURL:imageURL
sourceURL:sourceURL
description:[NSString stringWithFormat:#"%#",product.SKU_Name]];
Related
i have pdf file name now i want to open that pdf file from my ipad device with compatable application...
NSString *fileurl=[FILE_URL_Array objectAtIndex:indexPath.row];
NSArray *parts = [fileurl componentsSeparatedByString:#"/"];
NSString *filename = [parts lastObject];
NSString *extn =[filename pathExtension];
NSLog(#"file extn is %#",extn);
NSURL *url = [NSURL URLWithString:fileurl];
NSLog(#"not existing url is %#",url);
NSData *urlData = [NSData dataWithContentsOfURL:url];
now i want to open this file in my ipad device..when i click on it..can any one have idea?...Thanks in advance
You can use UIwebview to load it. Check out the answers on this post a while back. opening pdf
you can load your pdf on webview
NSURLRequest *req = [[NSURLRequest alloc] initwithUrl:url];
[self.webview loadRequest:req];
Might be help you...
// Your code
NSString *fileurl=[FILE_URL_Array objectAtIndex:indexPath.row];
NSArray *parts = [fileurl componentsSeparatedByString:#"/"];
NSString *filename = [parts lastObject];
NSString *extn =[filename pathExtension];
NSLog(#"file extn is %#",extn);
NSURL *url = [NSURL URLWithString:fileurl];
// Take a web view and load the url in the web view
NSURLRequest *request = [NSURLRequest url];
dispatch_async(dispatch_get_main_queue(), ^{
[_webView loadRequest:request]; // UIWebView object declared globally
});
Happy coding...
PDF file can open by UIWebView and WKWebView, you just load the PDF file by a NSURL.
how to convert Nsurl Domain to my country domain
Example :
NSURL *url = [NSURL URLWithString:#"http://www.google.com"];
How can get some thing like http://www.google.com.eg
it can detect my zone and change it with my domain zone, if website support multi zones domain.
If there isn't a path in the url just append .eg to the end of the string.
NSString *newCountryString = [[url absoluteString] stringByAppendingString:#".eg"];
NSURL *newCountryUrl = [NSURL URLWithString:newCountryString];
If the url has a path do this:
NSString *host = [url host];
NSString *domain = [[host componentsSeparatedByString:#"."] lastObject];
NSString *newCountryString = [[url absoluteString] stringByReplacingOccurrencesOfString:domain withString:[domain stringByAppendingString:#".eg"]];
NSURL *newCountryUrl = [NSURL URLWithString:newCountryString];
i am NewBie in iOS Development. I want to Decode my NSURL With Pagination Here my Url Like as
http://www.janvajevu.com/webservice/categorylist.php?category=%E0%AA%B8%E0%AB%8D%E0%AA%B5%E0%AA%BE%E0%AA%B8%E0%AB%8D%E0%AA%A5%E0%AA%AF&page=0
And i Decode this URL Like as
NSURL *urls = [NSURL URLWithString:#"http://www.janvajevu.com/webservice/categorylist.php?category=%E0%AA%B8%E0%AB%8D%E0%AA%B5%E0%AA%BE%E0%AA%B8%E0%AB%8D%E0%AA%A5%E0%AA%AF&page=0"];
NSString *urlString = [urls absoluteString];
NSLog(#"UrlString %#",urlString);
NSURL * url=[NSURL URLWithString:urlString];
But it Give me Only 0 Page Url i want to Like as make my url as
NSURL *urls=[NSURL URLWithString:#"My Url &page=%d",pagenum];
Here i want at place of My Url as Decoding of my Original Url If it is Possible then Please Give me Solution for it.
you are doing it in wrong way.
this is the right way
NSString *urlString = #"http://www.janvajevu.com/webservice/categorylist.php?category=%E0%AA%B8%E0%AB%8D%E0%AA%B5%E0%AA%BE%E0%AA%B8%E0%AB%8D%E0%AA%A5%E0%AA%AF&page=";
NSURL *targetURL = [NSURL URLWithString:[NSString stringWithFormat:#"%#%d",urlString,pageNumber]];
NSLog(#"targetURL is : %#",targetURL);
Hope this will help you..
NSString *str=#"http://www.janvajevu.com/webservice/categorylist.php?category=%E0%AA%B8%E0%AB%8D%E0%AA%B5%E0%AA%BE%E0%AA%B8%E0%AB%8D%E0%AA%A5%E0%AA%AF&page=0";
NSString *result =[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *urls = [NSURL URLWithString:result] ;
Im trying to get an image from a url link.
NSURL *thmbnailUrl = [NSURL URLWithString:[NSString stringWithFormat:#"http://%#:800/fishtune/movie/%#.png",[[DBHelper sharedInstance] currentHostIP],[arr objectAtIndex:0]]];
NSLog(#"thmbnail:%#",[NSString stringWithFormat:#"http://%#:800/fishtune/movie/%#.png",[[DBHelper sharedInstance] currentHostIP],[arr objectAtIndex:0]]);
NSData *data = [NSData dataWithContentsOfURL:thmbnailUrl];
NSLog(#"movimgdata:%#",data);
UIImage *img = [[UIImage alloc]initWithData:data];
NSLog(#"movimg:%#",data);
NSData *imgData = UIImagePNGRepresentation(img);
when i log thmbnail i get this "ipofserverinnetwork/fishtune/movie/Our Logo 480p back.png"
Note:i didn't put the original ip.
I get null when i log data and of course img will also be null. I really dont know why I'm getting null. because when I tried entering the url in a browser it displays the image. I used the same code in another part of my app and it works but when i used it in this it fails. Is it because of the spaces between "Our_Logo_480p"?
you might need to use
NSString* escapedUrl = [yourstring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
yes it's because of spaces, use
NSString *myUrl = [NSString stringWithFormat:#"http://%#:800/fishtune/movie/%#.png",[[DBHelper sharedInstance] currentHostIP],[arr objectAtIndex:0]];
NSString *url = [myUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
Here is my code and it gives "Program received signal "SIGABRT".
I'm new at iOS Development.
- (IBAction)getData {
NSURL *URL = #"http://www.oeslabs.com/aa.txt";
NSData *data = [NSData dataWithContentsOfURL:URL];
NSString *string = [NSString stringWithUTF8String:[data bytes]];
if (string == nil) {
// an error occurred
label1.text =#"Error";
}
else{
label1.text = string;
}
}
You Also Can put code as
NSString *urlString = [NSString stringWithFormat:#"http://www.oeslabs.com/aa.txt"];
NSURL *myUrl = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
.
.
.
.
.
Here is Official Documentation of stringByAddingPercentEscapesUsingEncoding. use for convert the legal URL string.
You are trying to assign NSString
to NSURL
replace
NSURL *URL = #"http://www.oeslabs.com/aa.txt";
With
NSURL *URL = [NSURL URLWithString:#"http://www.oeslabs.com/aa.txt"];