Call NSSharingService from FinderSync extension

107 views Asked by At

I am trying to send an email(open the default mail client application) from my FinderSync extension.

        let service = NSSharingService(named: NSSharingService.Name.composeEmail)
        if(service != nil)
        {
            service!.recipients = ["[email protected]"]
            service!.subject = "Test Mail"
           if service!.canPerform(withItems: ["Test Mail body"])
           {
                service!.perform(withItems: ["Test Mail body"])
           }
           else
           {
                  //fail for me
          }
        }

The same code executes from AppDelegate/ViewController while starting the main application but not working when calling from the extension.

1

There are 1 answers

4
Marek H On BEST ANSWER

FinderSync is an NSExtension which is not allowed to use NSSharingService

/* @class SHKSharingService (ShareKit.framework) */  

-(char)canPerformWithItems:(NSArray *)items {
    if (([[SHKSharingService class] isShareKitPlugInService] || ([items count] > 0x1388)) {
    return NO;
}

isShareKitPlugInService is defined as

[[NSBundle mainBundle] infoDictionary][@"NSExtension"]