Iphone iOS应用程序与pinterest的集成

Iphone iOS应用程序与pinterest的集成,iphone,objective-c,ios,pinterest,Iphone,Objective C,Ios,Pinterest,当前允许iOS应用共享pinterest的最可靠的方法是什么 Pinterest API尚未公开,唯一建议分享的方式是他们的web按钮。我也看了很多东西。我甚至联系了Pinterest团队关于SDK的事宜。我找到的最接近的东西是github上的PHP包装器 但这不是最好的解决方案,因为它是非官方api,很可能会崩溃。我在iPad应用程序中集成了pinterest。但是,因为Pinterest还没有用于发布的API,所以我使用了以下方法。我只是以编程方式创建一个HTML网页,并以编程方式向该网页添

当前允许iOS应用共享pinterest的最可靠的方法是什么


Pinterest API尚未公开,唯一建议分享的方式是他们的web按钮。

我也看了很多东西。我甚至联系了Pinterest团队关于SDK的事宜。我找到的最接近的东西是github上的PHP包装器


但这不是最好的解决方案,因为它是非官方api,很可能会崩溃。

我在iPad应用程序中集成了pinterest。但是,因为Pinterest还没有用于发布的API,所以我使用了以下方法。我只是以编程方式创建一个HTML网页,并以编程方式向该网页添加一个Pin-it按钮。然后我显示一个Web视图,并允许用户再次单击锁定它。这些是更多的解释步骤

1) 创建具有UIWebView的WebViewController。添加关闭按钮、添加UIWebViewDelegateProtocol、微调器、htmlString属性

2) 当用户单击应用程序中的“锁定”按钮时,以编程方式生成HTML以放入该UIWebView。在本例中,我将不同产品的不同图像放入HTML页面

- (NSString*) generatePinterestHTMLForSKU:(NSString*)sku {
NSString *description = @"Post your description here";

// Generate urls for button and image
NSString *sUrl = [NSString stringWithFormat:@"http://d30t6wl9ttrlhf.cloudfront.net/media/catalog/product/Heros/%@-1.jpg", sku];
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;
}
4) 在WebViewController上放置一个“关闭”按钮以关闭它。还可以添加微调器来跟踪UIWebView的加载

- (IBAction)closeClicked:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}

另外,我用同样的方法将Google Plus的+1按钮添加到iPad应用程序中。(它也没有发布API,目前只有只读API)

如果您只想共享(即用户板上的pin),那么您可以使用iphone URL方案并调用Pinterest应用程序以及参数URL(页面URL到pin)、媒体(图像URL到pin)和说明(待锁定页面的说明)。如果用户尚未安装,则提供UIAlertView并将其转发至appstore以下载官方Pinterest应用程序

参考

打开Pinterest应用程序的代码:

NSURL *url = [NSURL URLWithString:@"pinit12://pinterest.com/pin/create/bookmarklet/?url=URL-OF-THE-PAGE-TO-PIN&media=URL-OF-THE-IMAGE-TO-PIN&description=ENTER-YOUR-DESCRIPTION-FOR-THE-PIN"];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
    [[UIApplication sharedApplication] openURL:url];
}else {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Pinterest" message:@"Would you like to download Pinterest Application to share?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Continue", nil];
    [alert show];
}
UIAlertViewDelegate方法

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1){
        NSString *stringURL = @"http://itunes.apple.com/us/app/pinterest/id429047995?mt=8";
        NSURL *url = [NSURL URLWithString:stringURL];
        [[UIApplication sharedApplication] openURL:url];
    }
}

我尝试将Pinterest与自定义URL方案集成,也在我的设备上下载Pinterest应用程序,但没有abel与之集成

问题是,我不想使用webView进行集成,所以有可能做到这一点,我在app store上没有发现任何具有pinterest集成的应用程序

我也用谷歌搜索过,但更糟糕的是,Snapguide还从应用程序中删除了pinterest集成

我使用webView代码锁定图像,无需打开完整的Pinterest网站

NSString *urlStr =[NSString stringWithFormat:@"http://pinterest.com/pin/create/bookmarklet/?url=www.<domainname>.com&media=http://<domainname>.files.com/hello.jpg?w=495&description=hello"];
NSString*urlStr=[NSString stringWithFormat:@”http://pinterest.com/pin/create/bookmarklet/?url=www..com&media=http://.files.com/hello.jpg?w=495&description=hello"];

这将很容易,但有了webView,这是我不想要的。

截至2013年5月20日,Pinterest已经发布了用于固定内容的iOS SDK


查看以了解更多信息。

@mydogisbox web按钮对用户来说很不方便,因为您必须在网站上显示额外的web视图并呈现某种移动优化页面。请注意使用此代码的任何人-注意编码字符串的百分比,以及使用格式字符串创建字符串但只传递静态字符串的冗长性字符串。我尝试了这段代码,但canOpenUrl始终返回否,尽管我已经在我的设备上安装了Pinterest。我想可能是因为我已经在facebook、google+上实现了共享功能,…是否应该向AppDelegate方法-(BOOL)应用程序:(UIApplication*)应用程序openURL:(NSURL*)添加一些内容url sourceApplication:(NSString*)sourceApplication注释:要打开Pinterest应用程序?这在新api中不再有效。有人有示例代码的url吗?需要查找有关如何执行的更多详细信息吗?是否转到我文章中的链接?如果单击“iOS SDK”,应该可以找到所需内容。
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1){
        NSString *stringURL = @"http://itunes.apple.com/us/app/pinterest/id429047995?mt=8";
        NSURL *url = [NSURL URLWithString:stringURL];
        [[UIApplication sharedApplication] openURL:url];
    }
}
NSString *urlStr =[NSString stringWithFormat:@"http://pinterest.com/pin/create/bookmarklet/?url=www.<domainname>.com&media=http://<domainname>.files.com/hello.jpg?w=495&description=hello"];