2017-05-24 4 views
0

Ich versuche, Bild auf Instagram zu teilen. Dokumentation (https://www.instagram.com/developer/mobile-sharing/iphone-hooks/) sagt über UTI "com.instagram.exclusivegram" und Bild-Erweiterung "igo" nur für die Instagram-Show. Aber UIDocumentInteractionController zeigt viele Optionen für mich. Nicht nur Instagram. Hast du irgendwelche Möglichkeiten, direkt mit Instagram zu teilen? (Siehe einzelne Option in UIDocumentInteractionController)Instagram iPhone Bild teilen

UIDocumentInteractionController *docInteraction=[UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:@".../image.igo"]]; 
[email protected]"com.instagram.exclusivegram"; 
BOOL presented=[docInteraction presentOpenInMenuFromRect:CGRectMake(0, self.view.frame.size.height-1, self.view.frame.size.width, 1) 
                inView:self.view 
               animated:YES]; 

screenshot

+0

versuchen, dies offen instagram direkt ist NSURL * instagramURL = [NSURL URLWithString: [NSString string: @ "instagram: // Bibliothek Local =% @", asset.localIdentifier]]; if ([[UIApplication sharedApplication] canOpenURL: instagramURL]) { [[UIApplication sharedApplication] openURL: instagramURL]; } else { NSLog (@ "Instagram nicht gefunden"); } – Birendra

Antwort

0

Verwenden Sie diese unter Klasse in Instagram zu teilen und es ist 100%.

Dateiname: InstagramSharing.h

#import <Foundation/Foundation.h> 
#import <UIKit/UIKit.h> 

@interface InstagramSharing : NSObject <UIDocumentInteractionControllerDelegate> 
+ (InstagramSharing*)sharedData; 

@property (nonatomic, retain) UIDocumentInteractionController *documentController; 

-(void)instaGramWallPost:(NSString *)imgName andExt:(NSString *)ext inViewController:(UIViewController *)viewController; 

@end 

Dateiname: InstagramSharing.m

#import "InstagramSharing.h" 


@implementation InstagramSharing 
+ (id) sharedData 
    { 
     static InstagramSharing *singletonInstance = nil; 
     static dispatch_once_t onceToken; 

     dispatch_once(&onceToken, ^{ 
      if(!singletonInstance) { 
       singletonInstance = [[InstagramSharing alloc] init]; 
      } 
     }); 

     return singletonInstance; 
    } 

-(NSString*) getFilePath:(NSString *)fileName{ 
     // NSString *searchFilename = @"hello.pdf"; // name of the PDF you are searching for 

     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
     NSString *documentsDirectory = [paths objectAtIndex:0]; 
     NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager] enumeratorAtPath:documentsDirectory]; 

     NSString *documentsSubpath; 
     while (documentsSubpath = [direnum nextObject]) 
     { 
      if (![documentsSubpath.lastPathComponent isEqual:fileName]) { 
       continue; 
      } 

      NSLog(@"found %@", documentsSubpath); 
     } 
     return documentsSubpath; 
    } 

-(void)instaGramWallPost:(NSString *)imgName andExt:(NSString *)ext inViewController:(UIViewController *)viewController 
    { 
     NSString *path = [[NSBundle mainBundle] pathForResource:imgName ofType:ext]; 
     NSURL *myURL = [NSURL fileURLWithPath:path]; 

     NSData * imageData = [[NSData alloc] initWithContentsOfURL:myURL]; 
     UIImage *imgShare = [[UIImage alloc] initWithData:imageData]; 

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

     if([[UIApplication sharedApplication] canOpenURL:instagramURL]) //check for App is install or not 
     { 
      UIImage *imageToUse = imgShare; 
      NSString *documentDirectory=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; 
      NSString *saveImagePath=[documentDirectory stringByAppendingPathComponent:@"Image.igo"]; 
      NSData *imageData=UIImagePNGRepresentation(imageToUse); 
      [imageData writeToFile:saveImagePath atomically:YES]; 
      NSURL *imageURL=[NSURL fileURLWithPath:saveImagePath]; 

      NSString *path = [[NSBundle mainBundle] pathForResource:imgName ofType:ext]; 
      NSURL *url = [NSURL fileURLWithPath:path]; 

      self.documentController=[[UIDocumentInteractionController alloc]init]; 
      self.documentController = [UIDocumentInteractionController interactionControllerWithURL:imageURL]; 
      self.documentController.delegate = self; 
      self.documentController.annotation = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Testing"], @"InstagramCaption", nil]; 
      self.documentController.UTI = @"com.instagram.exclusivegram"; 
      UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController; 
      [self.documentController presentOpenInMenuFromRect:CGRectMake(1, 1, 1, 1) inView:viewController.view animated:YES]; 
     } 
     else { 
      //   DisplayAlertWithTitle(@"Instagram not found", @"") 
      NSLog(@"no image found"); 
     } 
    } 



@end 

Wie unter Leitung

Auf Teilen Aktionsaufruf verwenden

[[InstagramSharing sharedData] instaGramWallPost:@"nature1" andExt:@"jpeg" inViewController:self]; 
+0

Nein. Es ist vorhanden Dialog mit wenigen Anwendungen. Nicht nur Instagram. – user3026863

+0

@ user3026863 Hat dich nicht bekommen. –

Verwandte Themen