Skip to content

Instantly share code, notes, and snippets.

@millenomi
Created August 20, 2011 12:56
Show Gist options
  • Save millenomi/1159072 to your computer and use it in GitHub Desktop.
Save millenomi/1159072 to your computer and use it in GitHub Desktop.
SwapKit 2 code doodles
// ----- simplest: -----
- (void) application:(id) app didFinishLaunchingWithOptions:(NSDictionary*) opts;
{
...
services = [ILServicesController new];
services.showsServicesActionInMenu = YES;
// with this, all menus will show a Services… command at the end.
// you can easily tap into this by implementing a UIResponder action in your view or view controller subclass, and let SwapKit's default impl manage everything for you. Just show the menu as you would for cut/copy/paste.
// SK2 contains default implementations of this for UIKit text controls, so they work without writing any extra code!
...
}
// ----- more control: -----
- (void) sendSomeImageToSwapKit {
ILServiceIntent* intent = [ILServiceIntent intentForSendingImage:self.selectedImage action:kILServiceActionAny];
[services invokeServiceForIntent:intent fromViewController:self.window.rootViewController];
}
// ----- even more control: -----
- (void) sendSomeTextToSwapKit {
ILServiceIntent* intent = [ILServiceIntent intentForSendingSubstringOfEditedText:self.textField.text selectedRange:self.textField.selectedRange action:kILServiceActionAny];
// The above would allow SwapKit to show service entries for "selection", "paragraph", "entire document" etc in the picker automatically.
ILServiceInvocationController* invo = [services controllerForInvokingServiceForIntent:intent];
invo.delegate = self;
[invo proceed];
}
- (ILServiceInvocationPresentationStyle) presentationStyleForInvocationController:(id) ctl;
{
return kILServiceInvocationPresentationModal; // on iPad, causes any view controller shown to be displayed as a modal view controller instead of a popover
}
- (void) presentModalViewController:(id) vc forInvocationController:(id) ctl;
{
vc.modalPresentationStyle = // blah, customize customize
[self.window.rootViewController presentModalViewController:vc animated:YES];
}
- (void) dismissModalViewController:(id) vc forInvocationController:(id) ctl;
{
[vc dismissModalViewControllerAnimated:YES];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment