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
URLの読み込みを間違えましたか? また、常に認証を求められます。どうすればそれを回避できますか?