使用UIDocumentInteractionController时,请点击“在Instagram中打开”

时间:2013-05-15 17:16:51

标签: ios objective-c instagram

我有以下课程:

.h文件:

#import <Foundation/Foundation.h>

@interface CHTInstagramSharer : NSObject<UIDocumentInteractionControllerDelegate>
@property (nonatomic, retain) UIDocumentInteractionController *dic;
-(void) sharePic:(UIImage *)image;
@end

.m文件

#import "CHTInstagramSharer.h"
#import <UIKit/UIKit.h>
#import "BaseController.h"

@implementation CHTInstagramSharer


-(void) sharePic:(UIImage *)image{    

    NSString * jpgPath = [Utils saveImage:image toFile:@"cover.igo"];
    NSURL *url = [NSURL fileURLWithPath:jpgPath];
    self.dic = [UIDocumentInteractionController interactionControllerWithURL: url];
    self.dic.UTI = @"com.instagram.exclusivegram";
    self.dic.delegate = self;
    self.dic.annotation = [NSDictionary dictionaryWithObject:@"Caption Test" forKey:@"InstagramCaption"];
    [self.dic presentOpenInMenuFromRect:CGRectMake(0, 0, 320, 44)    inView:[BaseController sharedInstance].view animated: YES ];
}
@end

它向控制器显示“在Instagram中打开”选项,但是当我点击它时,应用程序崩溃了。

知道为什么吗?

补充信息,当我查看调试器中的url时,我得到: 文件://localhost/var/mobile/Applications/53435781-3BAB-4B02-A80C-FC088F696AE8/Library/Caches/cover.igo

当我查看堆栈跟踪时,崩溃似乎发生在[_UIOpenWithAppActivity performActivity]中。

2 个答案:

答案 0 :(得分:8)

看起来您没有保留文档控制器。我像这样使用Instagram钩子:

编辑:修改为ARC

- (void)sharePic:(UIImage *)image {

    NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"Image.ig"];
    NSData *imageData = UIImageJPEGRepresentation(image, 0.8);
    [imageData writeToFile:savedImagePath atomically:YES];
    NSURL *imageUrl = [NSURL fileURLWithPath:savedImagePath];

    UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:imageUrl];
    [docController retain];
    docController.UTI = @"com.instagram.exclusivegram";
    docController.delegate = self;
    docController.annotation = [NSDictionary dictionaryWithObject:@"Caption Test" forKey:@"InstagramCaption"];
    [docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
    docController = nil;
}

如果有帮助,请告诉我。

答案 1 :(得分:0)

我也面临同样的问题,声明-(void)textFieldDidBeginEditing:(UITextField *)textField { if (textField == txtText ) { pktStatePicker = arrMsg; } else if (textField == currency1 ) { pktStatePicker = currencyname1; } [pktStatePicker reloadAllComponents]; 上的UIDocumentInteractionController *docController通常为我工作!

@interface

希望这有帮助! :)