Pinterest集成在ios应用程序中?

时间:2013-02-07 13:52:19

标签: iphone ios xcode webview pinterest

我正试图从我的应用程序发布图像上的pinterest.From过去五天我在寻找完美的解决方案后,最后发布了一些问题,现在我离我很远,以解决我的问题。问题是当我发布任何图像使用url成功地将我的图像发布在pinterest上,如下面的代码所示。

-(NSString*) generatePinterestHTML {
NSString *description = @"Post your description here";
NSString *sUrl = [NSString stringWithFormat:@"http://4.bp.blogspot.com/-w4oTZjlpgwo/T5_pi-KJPuI/AAAAAAAAAoM/rKm3E0XCbgY/s1600/flower.png"];
NSLog(@"URL:%@", sUrl);
NSString *protectedUrl = (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,(__bridge CFStringRef)sUrl, NULL, (CFStringRef)@"!'\"();:@&=+$,/?%#[]% ",CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));
NSLog(@"Protected URL:%@", protectedUrl);
NSString *imageUrl = [NSString stringWithFormat:@"\"%@\"", sUrl];
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\"><a href=%@ class=\"pin-it-button\" count-layout=\"horizontal\"><img border=\"0\" src=\"http://assets.pinterest.com/images/PinExt.png\" title=\"Pin It\" /></a></p>", buttonUrl];
[htmlString appendFormat:@"<p align=\"center\"><img width=\"400px\" 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;
}
-(void)viewDidLoad
{
 [super viewDidLoad];
NSString *htmlString = [self generatePinterestHTML];
NSLog(@"Generated HTML String:%@", htmlString);
mywebview.backgroundColor = [UIColor clearColor];
mywebview.opaque = NO;
if ([mywebview isHidden]) {
    [mywebview setHidden:NO];
}
[mywebview loadHTMLString:htmlString baseURL:nil];
}

以下屏幕截图显示我的上述代码结果

enter image description here enter image description here

但是,当我尝试从我的应用程序上传图像时,这不正常,这是我的代码

 - (void)viewDidLoad
 {
 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
savedImagePath = [[documentsDirectory stringByAppendingPathComponent:@"savedImage.png"] mutableCopy];
NSLog(@"savedImagePath..%@",savedImagePath);
NSData*  imageData = UIImagePNGRepresentation(mypimage);
[imageData writeToFile:savedImagePath atomically:YES];
[super viewDidLoad];
NSString *htmlString = [self generatePinterestHTML];
NSLog(@"Generated HTML String:%@", htmlString);
mywebview.backgroundColor = [UIColor clearColor];
mywebview.opaque = NO;
if ([mywebview isHidden]) {
    [mywebview setHidden:NO];
}
[mywebview loadHTMLString:htmlString baseURL:nil];
}
- (NSString*) generatePinterestHTML {
NSString *description = @"Post your description here";
NSString *stringUrl = [NSString stringWithFormat:@"%@",savedImagePath];
NSLog(@"stringUrl:%@", stringUrl);
NSURL *urlToUpload = [[NSURL alloc]initFileURLWithPath:stringUrl];
NSString* sUrl = [NSString stringWithFormat:@"%@",urlToUpload];
NSString *protectedUrl = (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,(__bridge CFStringRef)sUrl, NULL, (CFStringRef)@"!'\"();:@&=+$,/?%#[]% ",CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));
NSLog(@"Protected URL:%@", protectedUrl);
NSString *imageUrl = [NSString stringWithFormat:@"\"%@\"", sUrl];
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\"><a href=%@ class=\"pin-it-button\" count-layout=\"horizontal\"><img border=\"0\" src=\"http://assets.pinterest.com/images/PinExt.png\" title=\"Pin It\" /></a></p>", buttonUrl];
[htmlString appendFormat:@"<p align=\"center\"><img width=\"400px\" 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;
}

对于上面的代码我的截屏结果是 link1 link2所以请建议任何解决此问题的方法。谢谢

1 个答案:

答案 0 :(得分:2)

在服务器上发布图像并将相应的URL地址分配到pinit按钮后,它对我有用。 我发布了我的答案here,以便那些最有可能在apptest上发布本地图片的人。

希望它对所有人都有帮助。

由于