Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize SLComposeServiceViewController pop up of share extension iOS 8

I Have integrated share extension in my app but I want to do few modification in the SLComposeServiceViewController pop up as per the project requirement like change the button titles and set background colour for text view and header. How do I do that?

like image 774
iMash Avatar asked Oct 14 '14 13:10

iMash


3 Answers

I am answering my question if someone could help this out. After gone through many articles and reading I have come up with following solution. Because there is not enough content to try.

I change base class SLComposeServiceViewController as UIViewController so that I can do some customisation. So as we know we can add popup like evernote also we can apply animationt to that popup.

You can get post method callback in viewddidload method of your viewController.Where you can do something like this:

- (void)viewDidLoad {
    NSExtensionItem *item = self.extensionContext.inputItems.firstObject;
    NSItemProvider *itemProvider = item.attachments.firstObject;

    if ([itemProvider hasItemConformingToTypeIdentifier:@"public.url"]) {
        [itemProvider loadItemForTypeIdentifier:@"public.url"
                                        options:nil
                              completionHandler:^(NSURL *url, NSError *error) {
                                  NSString *urlString = url.absoluteString;
                                  NSLog(@"%@",urlString);

                          }];
    }
}

From above code you can obtain url link. for more information to get image and other things best to refer only apple documentation.

Apple Documentation

like image 195
iMash Avatar answered Nov 11 '22 19:11

iMash


To change the Post button text, here's a Swift solution that should most likely pass review (caveat being I haven't tried yet). Do it in an SLComposeServiceViewController subclass:

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    // Reset Post button text.
    for item in (self.navigationController?.navigationBar.items)! {
        if let rightItem = item.rightBarButtonItem {
            rightItem.title = "Save"
            break
        }
    }
}
like image 25
Will Dinkel Avatar answered Nov 11 '22 18:11

Will Dinkel


You can change e.g. button titles of SLComposeServiceViewController by doing this:

class CustomServiceViewController: SLComposeServiceViewController {
    override func viewDidLoad() {
        let navigationBar = view.subviews.first?.subviews?.last? as? UINavigationBar
        let postButton = navigationBar?.subviews.last? as? UIButton
        let cancelButton = navigationBar?.subviews.last? as? UIButton
        postButton?.setTitle("Done", forState: .Normal)
    }
}

Be warned - it's a fragile solution, based on undocumented internals of SLComposeServiceViewController

like image 32
average Joe Avatar answered Nov 11 '22 17:11

average Joe