venu
venu

Reputation: 2979

IOS App Action extension is not closing

I am facing app extension close issues , please tell me if anyone know what wrong am doing.I am using action extension after preform some action inside extension i need to return response back.

Sample Code

// 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];
}

With Success Case working fine but some time is not closing, With Error Case not working above code. Please let me know what went wrong.Thanks

Upvotes: 2

Views: 1811

Answers (1)

Matthew
Matthew

Reputation: 41

When you create an action extension, this is the default method which will close the Action Extension View Controller:

- (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];
}

Since this method is already provided, you should just try calling it from your success method.

// 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];
}

Upvotes: 1

Related Questions