Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 禁用UIDocumentController中的某些服务_Iphone_Ios_Objective C_Ipad - Fatal编程技术网

Iphone 禁用UIDocumentController中的某些服务

Iphone 禁用UIDocumentController中的某些服务,iphone,ios,objective-c,ipad,Iphone,Ios,Objective C,Ipad,我有以下代码将照片发布到instagram: NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); NSString* homePath = [paths objectAtIndex:0]; NSString* basePath = @"integration/instagram"; NSString* tmpFileName =

我有以下代码将照片发布到instagram:

NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
    NSString* homePath = [paths objectAtIndex:0];
    NSString* basePath = @"integration/instagram";
    NSString* tmpFileName = @"jumpto.ig";

    NSString* dirPath = [NSString stringWithFormat:@"%@/%@", homePath, basePath];
    NSString* docPath = [NSString stringWithFormat:@"%@/%@", dirPath, tmpFileName];

    //clear it out and make it fresh
    [[NSFileManager defaultManager] removeItemAtPath:docPath error:nil];
    if ([[NSFileManager defaultManager] createDirectoryAtPath:dirPath withIntermediateDirectories:YES attributes:nil error:nil]) {

        NSData* imgData = [self generateImageData:img];
        [[NSFileManager defaultManager] createFileAtPath:docPath contents:imgData attributes:nil];
        NSURL* url = [NSURL fileURLWithPath:docPath isDirectory:NO ];

        NSURL *instagramURL = [NSURL URLWithString:@"instagram://camera"];
        if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
            //imageToUpload is a file path with .ig file extension
            self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url];
            self.documentInteractionController.UTI = @"com.instagram.exclusivegram";
            self.documentInteractionController.delegate = self;
            self.documentInteractionController.annotation = [NSDictionary dictionaryWithObject:@"Caption Test" forKey:@"InstagramCaption"];
            [self.documentInteractionController presentOptionsMenuFromBarButtonItem:self.navigationItem.rightBarButtonItem animated:YES];
        }
    }

问题是,当我打开popover时,我会看到其他服务,如facebook/twitter/mail/print/assign to contact/copy/等。我如何使它只在Instagram中打开一个选项?

Instagram会同时侦听.jpg/.ig文件和一个名为
.igo
(仅限Instagram)的特殊扩展名。通过将文件名更改为.igo,列表中应仅显示instagram:

NSString* tmpFileName = @"jumpto.igo";
资料来源:

编辑:我认为你写文件的方式存在逻辑问题。不要使用NSFileManager写出此行的内容:

[[NSFileManager defaultManager] createFileAtPath:docPath contents:imgData attributes:nil];
尝试使用NSData对象本身将其写入到位:

[imgData writeToFile:docPath atomically:NO];

我不确定这会导致不同的文件,但我想知道
NSFileManager
创建包含数据的文件的方式是否与
NSData
直接写入数据的方式不同。

如果您只想支持特定的服务(Instagram),那么为什么要使用
UIDocumentInteractionController
?提供您自己的简单UI(可能是警报或行动表)。如果用户说是,那么你可以直接用正确的URL启动Instagram。为什么你不能禁用其他选项呢?因为你不能。这方面没有API。
UIDocumentInteractionController
的要点是向用户显示支持特定文件/UTI.BTW的所有可能应用程序-您确定没有混淆
UIDocumentInteractionController
UIActivityViewController
?rmaddy,您必须使用
UIDocumentInteractionController
在应用程序之间传递图像数据。此外,
UIActivityViewConroller
在这里也不起任何作用。Instagram提供了一个专用扩展(.igo)来限制其他应用程序出现在这个场景中。我将它改为.igo,我仍然看到其他服务非常奇怪。您是如何生成图像的<代码>UIImageJPEGRepresentation?我正在使用UIImage*img=UIGraphicsGetImageFromCurrentImageContext();然后是调用UIImageJPEGRepresentation(图像,1.0);好的,我们已经取得了一些进展。。当我把它改成你说的,它现在只显示instagram和mail。只需要扔掉那个邮件