2014-03-03 33 views
1

一起發佈instagram我通過文檔交互控制器管理將圖像發佈到Instagram。這也顯示了Dropbox,WhatsApp等共享選項。我不想要這些功能,我只想要Instagram。有沒有辦法以編程方式點擊Instagram按鈕,或刪除其他不需要的應用程序的按鈕? 預先感謝您的回答。在我的應用程序中直接與文檔交互控制器

編輯:這裏是代碼,包含「com.instagram.exclusivegram」的行,我設法只顯示Instagram,凹凸和Dropbox。我怎樣才能讓最後兩個消失?

-(void)ShareInstagram 
{ 

    [self storeimage]; 
    NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"]; 
    if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) 
    { 

     CGRect rect = CGRectMake(0 ,0 , 612, 612); 
     NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/15717.igo"]; 

     NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]]; 
     _dic.UTI = @"com.instagram.exclusivegram"; 
     _dic.delegate=self; 
     _dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self]; 
     _dic=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile]; 
     _dic.delegate=self; 
     [_dic presentOpenInMenuFromRect: rect inView: self.view animated: YES ]; 

     // [[UIApplication sharedApplication] openURL:instagramURL]; 
    } 
    else 
    { 
     // NSLog(@"instagramImageShare"); 
     UIAlertView *errorToShare = [[UIAlertView alloc] initWithTitle:@"Instagram unavailable " message:@"You need to install Instagram in your device in order to share this image" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 

     errorToShare.tag=3010; 
     [errorToShare show]; 
    } 
} 


- (void) storeimage 
{ 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,  NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"15717.igo"]; 
    UIImage *NewImg=[self resizedImage:_imageToTweet inImage:CGRectMake(0, 0, 612, 612) ]; 
    NSData *imageData = UIImagePNGRepresentation(NewImg); 
    [imageData writeToFile:savedImagePath atomically:NO]; 
} 


- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate 
{ 
    UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL]; 
    interactionController.delegate = self; 

    return interactionController; 
} 
+0

使用'UIDocumentInteractionController'是將讓用戶決定做什麼整點。如果您只需要Instragram,請使用其他解決方案。在這裏做一些搜索。有直接發佈到Instagram的現有話題很多。 – rmaddy

+0

我沒有找到關於直接發佈的任何信息。你能幫我一些鏈接嗎?謝謝。 – charles

+0

@charles,你有沒有找到解決方案,只顯示Instagram的? – Abhishek

回答

1

方法setupControllerWithURL:usingDelegate覆蓋_dic實例變量上述設定的屬性。

這些線路沒有影響:

_dic.UTI = @"com.instagram.exclusivegram"; 
_dic.delegate=self; 

首先實例UIDocumentInteractionController,然後設置其屬性:

NSURL *igImageHookFile = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@", jpgPath]]; 
_dic = [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile]; 
_dic.UTI = @"com.instagram.exclusivegram"; 
_dic.delegate = self; 

[_dic presentOpenInMenuFromRect:rect inView:self.view animated:YES]; 
+0

有沒有什麼方法可以在模擬器中進行測試,還是需要在手機上進行測試?是否有關於這些功能的用戶流程的任何文檔? IG開發網站缺乏這方面的內容。 – noobsmcgoobs

相關問題