0

我想在 Google+ 上与 Url 共享图片,而无需登录我的 iOS 应用程序。

我用过 :

NSString *temp = @"Hello World";

// Construct the Google+ share URL
NSURLComponents* urlComponents = [[NSURLComponents alloc]                                                      initWithString:@"https://plus.google.com/share"];
                urlComponents.queryItems = @[[[NSURLQueryItem alloc]
                                              initWithName:@"text"
                                              value:temp]];
NSURL* url = [urlComponents URL];

if ([SFSafariViewController class]) {
    // Open the URL in SFSafariViewController (iOS 9+)
    SFSafariViewController* controller = [[SFSafariViewController alloc]                                                               initWithURL:url];
    controller.delegate = self;
    [self presentViewController:controller animated:YES completion:nil];

} else {
    // Open the URL in the device's browser
    [[UIApplication sharedApplication] openURL:url];
}

我不知道如何使用相同的方法发送图像..

4

2 回答 2

1

回答这个问题可能为时已晚,但有人会很有用。

NSURL *shareURL = [NSURL URLWithString:@"https://example.com/image.jpg"];
urlComponents.queryItems = @[
        [[NSURLQueryItem alloc] initWithName:@"url" value:[shareURL absoluteString]],
        [[NSURLQueryItem alloc] initWithName:@"text" value:text]
    ];
于 2017-02-14T00:48:09.860 回答
1

斯威夫特 4.1

 let strKeyValue: String =  "https://example.com/image.jpg"

guard var urlComponents = URLComponents(string: "https://plus.google.com/share") else {
                return nil
   }    
 urlComponents.queryItems = [URLQueryItem(name: "url", value:strKeyValue),URLQueryItem(name: "text", value:"This is testing text")]

  let browserViewController = SFSafariViewController(url: urlComponents.url)

  browserViewController.delegate = self 

  present(browserViewController, animated: true)
于 2018-07-19T10:54:01.213 回答