IOS应用程序操作扩展未关闭

时间:2015-04-30 09:23:14

标签: objective-c ios8 ios8-extension ios8-share-extension

我正面临应用程序扩展关闭问题,请告诉我是否有人知道我在做什么错误。我在扩展程序中执行某些操作后我正在使用操作扩展我需要返回响应。

示例代码

// With Success Case
- (void) completeActionWithItems: (NSString *) response {
    NSExtensionItem *extensionItem = [[NSExtensionItem alloc] init];
    extensionItem.attachments = @[[[NSItemProvider alloc] response typeIdentifier: (NSString *)kUTTypePlainText]];
   [self.extensionContext completeRequestReturningItems: @[extensionItem] completionHandler: nil];
}


// With Error Case
- (void) completeActionWithError: (NSError *) error {
     [self.extensionContext cancelRequestWithError: error];
}

成功案例工作正常,但有些时间没有结束, 错误案例无法在代码上方运行。 请让我知道出了什么问题。谢谢

1 个答案:

答案 0 :(得分:1)

创建操作扩展时,这是关闭操作扩展视图控制器的默认方法:

- (IBAction)done {
// Return any edited content to the host app.
// This template doesn't do anything, so we just echo the passed in items.

[self.extensionContext completeRequestReturningItems:self.extensionContext.inputItems completionHandler:nil];
}

由于已经提供了此方法,您应该尝试从成功方法中调用它。

// With Success Case
- (void) completeActionWithItems: (NSString *) response {
NSExtensionItem *extensionItem = [[NSExtensionItem alloc] init];
extensionItem.attachments = @[[[NSItemProvider alloc] response typeIdentifier: (NSString *)kUTTypePlainText]];
   [self.extensionContext completeRequestReturningItems: @[extensionItem] completionHandler: nil];

// Call to "done" method
[self done];
}