【问题标题】:Pinterest integration in ios app?ios应用程序中的Pinterest集成?
【发布时间】:2013-02-07 13:52:18
【问题描述】:

我正在尝试在 pinterest 上发布我的应用程序中的图像。从过去五天开始,我在 SO 上发布了一些问题后终于找到了完美的解决方案,现在我离解决我的问题还有一点距离。问题是当我发布任何图像使用 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];
}

下面的屏幕截图显示了我上面的代码结果

但是当我尝试从我的应用上传图片时,它不能正常工作,这是我的代码

 - (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;
}

对于上面的代码,我的屏幕截图结果是 link1link2 所以请提出任何解决此问题的方法。谢谢

【问题讨论】:

    标签: iphone ios xcode webview pinterest


    【解决方案1】:

    在服务器上发布图像并为 pinit 按钮分配适当的 URL 地址后,它对我有用。 我将我的答案here发布给那些最有可能在 pinterest 上发布来自应用程序的本地图像的人。

    希望对大家有所帮助。

    谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-12
      • 1970-01-01
      相关资源
      最近更新 更多