7

I was using Pocket and they seem to have created a share extension that simply posts the URL to their service w/o a UI.

Anyone have an idea on how to replicate this? I'm new to extensions but very familiar with iOS/Objective-C

enter image description here

enter image description here

Brian L. Clark
  • 588
  • 5
  • 19

2 Answers2

13

Figured it out.

Just don't use the built in SLComposeServiceViewController

@interface ShareViewController : UIViewController

@end

And make sure to call the following function when done with the share extension

[self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];

In other words, replace the contents of ShareViewController.swift with:

import UIKit

class ShareViewController: UIViewController {
    override func viewDidLoad() {
        extensionContext?.completeRequest(returningItems: [], completionHandler: nil)
    }
}
Joshua C. Lerner
  • 1,910
  • 17
  • 12
Brian L. Clark
  • 588
  • 5
  • 19
  • 3
    It would be amazing to extend your answer with the complete example. Mayn thanks – elliotrock Mar 14 '16 at 06:06
  • Any example of this? if i do the same thing i keeps an overlay ontop of safari which cant be dismissed – andre de waard Jan 07 '21 at 13:57
  • 2
    Calling `completeRequest(returningItems:completionHandler:)` from `viewDidLoad()` didn't work for me in iOS 16, but calling it in `viewDidAppear(_:)` did work. – Larry Nov 09 '22 at 21:28
0

handle extension as per below below in share extension's viewdidload: works

[self.extensionContext completeRequestReturningItems:@[] completionHandler:blah];
wang wood
  • 1
  • 2