2014-01-17 3 views
21

Soweit ich weiß, haben Sie com.instagram.photo verwenden, um die allgemeinen Optionen und com.instagram.exclusivegram für die documentinteractioncontroller UTI, wenn Sie wirklich zu bekommen Nur Instagram + verwenden Sie die korrekte Erweiterung .ig für allgemeine und .igo für exklusive Instagram.Instagram Haken com.instagram.exclusivegram nicht so exklusiv

Aus irgendeinem Grund sehe ich mehrere Optionen und nicht nur Instagram wie ich will ..

Habe ich etwas vergessen? Ist es anders gemacht?

UIImage *image = (UIImage *)[info valueForKey:UIImagePickerControllerOriginalImage]; 

NSURL *instagramURL = [NSURL URLWithString:@"instagram://"]; 
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) { 
    CGRect rect = CGRectMake(0,0,0,0); 
    CGRect cropRect=CGRectMake(0,0,612,612); 
    // ig voor gewone instagram, igo voor exclusive instagram 
    NSString *jpgPath=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/temp/photo.igo"]; 
    CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], cropRect); 
    UIImage *img = [[UIImage alloc] initWithCGImage:imageRef]; 
    CGImageRelease(imageRef); 
    [UIImageJPEGRepresentation(img, 1.0) writeToFile:jpgPath atomically:YES]; 

    NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@",jpgPath]]; 
    // exclusive zou direct in de instagram app moeten openen, helaas toont hij meerdere opties met instagram ergenes helemaal achteraan 
    self.documentInteractionController.UTI = @"com.instagram.exclusivegram"; 
    self.documentInteractionController = [self setupControllerWithURL:igImageHookFile usingDelegate:self]; 
    self.documentInteractionController.annotation = [NSDictionary dictionaryWithObject:@"Alweer een Nostalgie deelnemer! #nostalgiebusje" forKey:@"InstagramCaption"]; 
    [self.documentInteractionController presentOpenInMenuFromRect: rect inView: self.view animated: YES ]; 
} 

Screenshot

+2

Ich habe das gleiche Problem ... – daidai

+0

Bitte stellen Sie Ihre 'setupControllerWithURL: usingDelegate:' Methode. Das Ergebnis dieser Methode wird der 'documentInteractionController' -Eigenschaft zugewiesen, nachdem Sie' UTI' string gesetzt haben. – vokilam

Antwort

5
self.documentInteractionController.UTI = @"com.instagram.exclusivegram"; 
self.documentInteractionController = [self setupControllerWithURL:igImageHookFile usingDelegate:self]; 

Es scheint, dass UTI String durch setupControllerWithURL:usingDelegate: Methode überschrieben wird.

2

Sie müssen eine temporäre Kopie des Bildes mit einer "ig" oder "ifo" Erweiterung erstellen, dann teilen Sie diese mit UTI "com.instagram.exclusivegram". Dies sollte die DocumentInteractionController nur mit der Option Instagram präsentieren:

if (![fm fileExistsAtPath:tempDirectory]) 
[fm createDirectoryAtPath:tempDirectory withIntermediateDirectories:YES attributes:nil error:nil]; 

NSString *tempInstagramPath = [tempDirectory stringByAppendingPathComponent:@"instagramShare.igo"]; 
if ([fm fileExistsAtPath:tempInstagramPath]) 
    [fm removeItemAtPath:tempInstagramPath error:nil]; 

[UIImageJPEGRepresentation(imageToShare, 1.0) writeToFile:tempInstagramPath atomically:NO]; 

documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:tempInstagramPath]]; 
documentInteractionController.delegate = self; 
documentInteractionController.UTI = @"com.instagram.exclusivegram"; 
documentInteractionController.annotation = @{@"InstagramCaption": @"My Photo Caption!"}; 
if (![documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated:YES]) 
    NSLog(@"Cannot open Document Interaction Controller for sharing with Instagram"); 
6

Mit Hilfe der Dateierweiterung igo korrekt ist, und die Anzahl der Anwendungen, die in der Liste angezeigt werden, ist wesentlich geringer, als wenn Sie ig verwendet. Von meinen Tests (nur iOS 9) machte die UTI keinen Unterschied zu der dargestellten Liste.

Sieht aus wie die iPhone hooks doc ist veraltet.