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?
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
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
}
}
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With