我正在尝试集成Pinterest
到我的 iOS 应用程序中。
这是我尝试过的。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewWillAppear:(BOOL)animated
{
[_pinterestWebView.scrollView setShowsHorizontalScrollIndicator:NO];
[_pinterestWebView.scrollView setShowsVerticalScrollIndicator:NO];
[super viewWillAppear:animated];
[self postToPinterestWithImageUrl:_url andDescription:_description];
}
-(void)postToPinterestWithImageUrl:(NSString *)url andDescription:(NSString *)description
{
NSString *buttonUrl = [NSString stringWithFormat:@"http://pinterest.com/pin/create/button/?url=http://www.flor.com&media=%@&description=%@", url, @"hello"];
[_pinterestWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:buttonUrl] cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:40]];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(@"WebView URL = %@",[request.URL absoluteString]);
return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
[_activityIndicator startAnimating];
[_activityIndicator setHidden:NO];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
NSRange range = [[webView.request.URL absoluteString] rangeOfString:@"login"];
if (range.location==NSNotFound) {
CGRect modifiedFrame = self.view.superview.frame;
CGPoint center = self.view.superview.center;
UIInterfaceOrientation orinetation= [[UIApplication sharedApplication] statusBarOrientation];
if (UIInterfaceOrientationIsLandscape(orinetation)) {
modifiedFrame.size=CGSizeMake(350, 650);
}
else
{
modifiedFrame.size=CGSizeMake(650, 350);
}
[self.view.superview setFrame:modifiedFrame];
[self.view.superview setCenter:center];
NSLog(@"Content Offset = %@",NSStringFromCGPoint(webView.scrollView.contentOffset));
[webView.scrollView setContentOffset:CGPointMake(40, 0)];
}
NSLog(@"Content Size = %@",NSStringFromCGSize([webView.scrollView contentSize]));
[_activityIndicator stopAnimating];
[_activityIndicator setHidden:YES];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(@"Error = %@",[error localizedDescription]);
}
- (void)viewDidUnload
{
[self setActivityIndicator:nil];
[self setPinterestWebView:nil];
[super viewDidUnload];
}
- (IBAction)dismissIt:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
-(BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}
但是,一旦 webview 加载了pinterest
登录页面并且如果我更改方向并尝试登录,那么我会在 webview 上显示以下消息。
可能是什么问题呢?我在加载Pinterest
网址时犯了任何错误吗?此外,它总是提示进行身份验证。我怎样才能避免这种情况?