簡體   English   中英

在ios上分享Instagram上的圖像

[英]Sharing Image on instagram in ios

我有一個應用程序,我在Instagram上分享圖像,它工作得非常好。

如截圖所示。 當我在Instagram上按下按鈕共享時,它會在UIActivityviewcontroller中打開。

是否有可能如果我點擊分享在Instagram上並且它直接帶我到本機Instagram應用程序?

如果用戶在其設備中安裝了其他應用程序,則應用程序也會因為UIActivityViewController而顯示。

我不想讓UIActivityviewcontroller顯示“在Instagram上打開”。

提前致謝。

在此輸入圖像描述

編輯

我正在截取視圖的截圖並在Instagram上分享該截圖。

當我點擊按鈕共享時,它會打開,如我不想要的屏幕截圖所示。

我使用以下代碼。

NSURL *instagramURL = [NSURL URLWithString:@"instagram://"];

                if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
                {
                    CGRect rect = CGRectMake(0 ,0 , 0, 0);
                    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
                    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

                    UIGraphicsEndImageContext();
                    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                    NSString* documentsDirectory = [paths objectAtIndex:0];

                    imagename=[NSString stringWithFormat:@"ff.ig"];
                    NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imagename];
                    ////NSLog(@"%@",fullPathToFile);

                    igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", fullPathToFile]];

                    self.dic.UTI = @"com.instagram.photo";
                    self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
                    self.dic=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];


                        self.dic.annotation = [NSDictionary dictionaryWithObject:@"Image" forKey:@"InstagramCaption"];

     [self.dic presentOpenInMenuFromRect: rect    inView:self.view animated: YES ];
  }

為了迅速

 var instagramURL = NSURL(string: "instagram://app")!
        if UIApplication.sharedApplication().canOpenURL(instagramURL) {
            var documentDirectory = NSHomeDirectory().stringByAppendingPathComponent("Documents")
            var saveImagePath = documentDirectory.stringByAppendingPathComponent("Image.igo")
            var imageData = UIImagePNGRepresentation(self.bestScoreShareView.takeSnapshot(W: 640, H: 640))
            imageData.writeToFile(saveImagePath, atomically: true)
            var imageURL = NSURL.fileURLWithPath(saveImagePath)!
           docController  = UIDocumentInteractionController()
            docController.delegate = self
            docController.UTI = "com.instagram.exclusivegram"
            docController.URL = imageURL
            docController.presentOpenInMenuFromRect(CGRectZero, inView: self.view, animated: true)

        } else {
            println("instagram not found")
        }

從uiview獲取shapshot的擴展

extension UIView {
    func takeSnapshot(#W: CGFloat, H: CGFloat) -> UIImage {
        var cropRect = CGRectMake(0, 0, 600, 600)
        UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.mainScreen().scale)
        drawViewHierarchyInRect(self.bounds, afterScreenUpdates: true)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        image.imageWithNewSize(CGSizeMake(W, H))
        return image
    }
}

設置圖像大小的擴展名

extension UIImage {
     func imageWithNewSize(newSize:CGSize) ->UIImage {
        UIGraphicsBeginImageContext(newSize)
        self.drawInRect(CGRectMake(0, 0, newSize.width, newSize.height))

        let newImage = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();
        return newImage
    }
}
self.documentInteractionController = [self setupControllerWithURL:imgurl usingDelegate:self];

self.documentInteractionController=[UIDocumentInteractionController  interactionControllerWithURL:imgurl];

self.documentInteractionController.UTI = @"com.instagram.exclusivegram";

以相同的順序使用此代碼。 這里documentInteractionController是UIDocumentInteractionController.just的對象,供您參考。 你只能在“打開”窗口中獲得Instagram。

使用igo擴展名而不是ig保存圖像。

這樣您只能在“打開方式”菜單中獲得instagram選項。

或者,如果您想在按下按鈕時直接打開Instagram,您可以傳遞應用程序的直接網址,它將引導您進入原生Instagram應用程序。

希望它能幫到你。

您是否檢查了圖像的大小。由於它支持大於612 * 612的圖像,請檢查您要發布的圖像的大小

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM