我試圖創建一個共享的應用程序擴展,並遵循從這個來源教程:共享擴展未出現在能夠共享照片的應用程序名單上的iPhone
http://www.technetexperts.com/mobile/share-extension-in-ios-application-overview-with-example/
我使用的XCode 8.0(8A218a )在模擬器上它按預期工作。在iOS 9.3.3的我的iPhone 5s上。
我先安裝容器應用程序,然後在XCode詢問「選擇要運行的應用程序」時選擇Photos應用程序來運行Extension。
現在,當我打開一張照片,同時延長運行時,出現以下錯誤:
MobileSlideShow[3500:589624] *** error reading settings archive file: <ISRootSettings:
/var/mobile/Documents/com.apple.mobileslideshow.settings/ISRootSettings_10.plist>
現在,當我點擊分享按鈕,我的容器的應用程序不會出現在應用程序的可共享的列表圖片。
編輯: 我分享一些代碼:
ShareViewController.m
@implementation ShareViewController
- (BOOL)isContentValid {
// Do validation of contentText and/or NSExtensionContext attachments here
return YES;
}
- (void)didSelectPost {
for (NSItemProvider* itemProvider in ((NSExtensionItem*)self.extensionContext.inputItems[0]).attachments) {
if([itemProvider hasItemConformingToTypeIdentifier:@"public.jpeg"]) {
NSLog(@"itemprovider = %@", itemProvider);
[itemProvider loadItemForTypeIdentifier:@"public.jpeg" options:nil completionHandler: ^(id<NSSecureCoding> item, NSError *error) {
NSData *imgData;
if([(NSObject*)item isKindOfClass:[NSURL class]]) {
imgData = [NSData dataWithContentsOfURL:(NSURL*)item];
}
if([(NSObject*)item isKindOfClass:[UIImage class]]) {
imgData = UIImagePNGRepresentation((UIImage*)item);
}
NSDictionary *dict = @{
@"imgData" : imgData,
@"name" : self.contentText
};
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.iosApp.testSharing"];
[defaults setObject:dict forKey:@"img"];
[defaults synchronize];
}];
}
}
}
@end
ViewController.m
@implementation ViewController
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.iosApp.testSharing"];
NSDictionary *dict = [defaults valueForKey:@"img"];
if (dict) {
NSData *imgData = [dict valueForKey:@"imgData"];
UIImage *image = [UIImage imageWithData:imgData];
[_shareImageView setImage:image];
_shareImageNameLabel.text = [dict valueForKey:@"name"];
[defaults removeObjectForKey:@"img"];
}
}
@end
你能分享一些相關的代碼嗎? – ystack