点击“在Instagram中打开"时崩溃在使用UIDocumentInteractionController时 [英] Crash wen tapping "Open in Instagram" while using UIDocumentInteractionController
问题描述
我有以下课程:
.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中打开"选项,但是当我点击该按钮时,该应用程序将崩溃.
It presents the controller with the option "Open in Instagram", but when I tap on that, the app crashes.
知道为什么吗?
补充信息,当我在调试器中查看url时,会得到: 文件://localhost/var/mobile/Applications/53435781-3BAB-4B02-A80C-FC088F696AE8/Library/Caches/cover.igo
Complementary information, when I look at the url in the debugger, I get: file://localhost/var/mobile/Applications/53435781-3BAB-4B02-A80C-FC088F696AE8/Library/Caches/cover.igo
当我查看堆栈跟踪时,崩溃似乎发生在[_UIOpenWithAppActivity performActivity]中.
The crash seems to happen in [_UIOpenWithAppActivity performActivity] when I look in the stack trace.
推荐答案
似乎您没有保留文档控制器.我使用Instagram钩子是这样的:
It looks like you are not retaining the document controller. I use the Instagram hook like this:
为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;
}
让我知道这是否有帮助.
Let me know if this helps.
这篇关于点击“在Instagram中打开"时崩溃在使用UIDocumentInteractionController时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!