Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/extensions/Variables/includes/ExtVariables.php on line 198

Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/extensions/Variables/includes/ExtVariables.php on line 198

Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/extensions/Variables/includes/ExtVariables.php on line 198

Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/extensions/Variables/includes/ExtVariables.php on line 198
ActionMenu: Difference between revisions - iPhone Development Wiki

ActionMenu: Difference between revisions

From iPhone Development Wiki
No edit summary
(copyediting and formatting)
Line 11: Line 11:
== Creating an Action Menu Plugin ==
== Creating an Action Menu Plugin ==


'''Requirements:'''
=== Requirements ===


* [http://iphonedevwiki.net/index.php/Theos/Getting_Started Theos installed]
* [[Theos/Getting_Started|Theos]] installed
* [https://ghostbin.com/paste/xgh6e ActionMenu.h]
* [https://ghostbin.com/paste/xgh6e ActionMenu.h]
* Some knowledge of Objective C or how DHowett would say: "LEARN OBJECTIVE-C FOR GODS' SAKES"
* Knowledge of Objective-C


'''What is an Action Menu Plugin?'''
=== What is an Action Menu Plugin? ===


* We basically implement a category of the UIResponder class which will be loaded by Action Menu
We implement a category of the UIResponder class which will be loaded by Action Menu. Action Menu also provides us with easy methods to register our new UIMenuController item.
* Action Menu also provides us with easy methods to register our new UIMenuController item


'''The Makefile'''
=== The Makefile ===


The resulting file is a dynamic library (.dylib) so we will create a Makefile for a Library.
The resulting file is a dynamic library (.dylib), so we will create a makefile for a library.


<source lang=c>
<source lang=c>
Line 39: Line 38:
</source>
</source>


We set the architecture to be armv7 and arm64 (64Bit). Then we include theos' common.mk file and after that we define the properties for our Library project.
We set the architecture to be armv7 and arm64 (64-bit). Then we include Theos' common.mk file, and after that we define the properties for our library project.


'''AMExample.h'''
=== AMExample.h ===


We will first create our Header File which will not have more than the category interface
We will first create our header file which will not have more than the category interface:


<source lang=objc>
<source lang=objc>
Line 54: Line 53:
</source>
</source>


'''AMExample.m'''
=== AMExample.m ===


We are going to implement the methods and then our category in the .m implementation File.
We are going to implement the methods and then our category in the .m implementation file.


First we simply include our Header File and write our @implementation section
First we include our header file and write our @implementation section:


<source lang=objc>
<source lang=objc>
Line 70: Line 69:
</source>
</source>


Using the NSObject's +(void)load method which will be executed earlier than any other method we implement so we can use this to initialize and create our UIMenuController Item.
Using the NSObject's +(void)load method which will be executed earlier than any other method, we implement so we can use this to initialize and create our UIMenuController item.


<source lang=objc>
<source lang=objc>
Line 93: Line 92:
</source>
</source>


Now we have to implement the canPerformAction and performMyAction method. The canPerformAction checks for the length of the selected Text and checks wether it is 0 or higher. It can only perform (return TRUE) if the selected text is longer than 0 characters.
Now we have to implement the canPerformAction and performMyAction method. The canPerformAction checks for the length of the selected text and checks wether it is 0 or higher. It can only perform (return TRUE) if the selected text is longer than 0 characters.


Now we have to implement the canPerformAction and performMyAction method to complete this Plugin:
Now we have to implement the canPerformAction and performMyAction method to complete this plugin:


<source lang=objc>
<source lang=objc>
Line 104: Line 103:
</source>
</source>


And in our performMyAction method we simply show an UIAlertView.
And in our performMyAction method we show an UIAlertView:


<source lang=objc>
<source lang=objc>
Line 122: Line 121:
</source>
</source>


To sum it up, +(void)load registers our Action Menu Item to be shown in the UIMenuController, - (BOOL)canPerformAction checks if there is any selected text and - (void)performMyAction will run our code when the Menu Item is selected.
To sum it up, +(void)load registers our Action Menu Item to be shown in the UIMenuController, - (BOOL)canPerformAction checks if there is any selected text, and - (void)performMyAction will run our code when the menu item is selected.


This is everything you need to know for your first Action Menu Plugin. All you need to do is change the actions that take place in the performMyAction method and you can customize your Plugin.
This is everything you need to know for your first Action Menu Plugin. All you need to do is change the actions that take place in the performMyAction method and you can customize your plugin.


== External links ==
== External links ==

Revision as of 22:07, 15 April 2014

ActionMenu
Cydia Package
Developer Ryan Petrich
Package ID actionmenu
Latest Version 1.2.14


ActionMenu is an extension that adds extra options to the menu that pops up when you select text or tap-and-hold an item (such as an image or a table cell).

Developers can integrate with it (by making a plugin) to add their own custom options to these menus.

Creating an Action Menu Plugin

Requirements

What is an Action Menu Plugin?

We implement a category of the UIResponder class which will be loaded by Action Menu. Action Menu also provides us with easy methods to register our new UIMenuController item.

The Makefile

The resulting file is a dynamic library (.dylib), so we will create a makefile for a library.

ARCHS = armv7 arm64

include theos/makefiles/common.mk

LIBRARY_NAME = AMExample
AMExample_FILES = AMExample.m
AMExample_INSTALL_PATH = /Library/ActionMenu/Plugins
AMExample_FRAMEWORKS = Foundation UIKit CoreGraphics

include $(THEOS_MAKE_PATH)/library.mk

We set the architecture to be armv7 and arm64 (64-bit). Then we include Theos' common.mk file, and after that we define the properties for our library project.

AMExample.h

We will first create our header file which will not have more than the category interface:

#import "ActionMenu.h" //import the Action Menu Header

@interface UIResponder (MyAwesomePlugin) //create our Category
- (BOOL)canPerformAction; //(we will check here if the selected text is longer than 0 characters)
- (void)performMyAction; //this method will do the actual 'work' of our Plugin
@end

AMExample.m

We are going to implement the methods and then our category in the .m implementation file.

First we include our header file and write our @implementation section:

#import "AMExample.h"

@implementation UIResponder (MyAwesomePlugin)

//our methods here

@end

Using the NSObject's +(void)load method which will be executed earlier than any other method, we implement so we can use this to initialize and create our UIMenuController item.

#import "AMExample.h"

@implementation UIResponder (MyAwesomePlugin)

+ (void)load {

/*
This will call Action Menu's registerAction:title:canPerform method 
which is Action Menu's extension to UIMenuController
*/

[[UIMenuController sharedMenuController] registerAction:@selector(performMyAction) 
                                                  title:@"Example" 
                                                  canPerform:@selector(canPerformAction)];

}

@end

Now we have to implement the canPerformAction and performMyAction method. The canPerformAction checks for the length of the selected text and checks wether it is 0 or higher. It can only perform (return TRUE) if the selected text is longer than 0 characters.

Now we have to implement the canPerformAction and performMyAction method to complete this plugin:

- (BOOL)canPerformAction {
//returns TRUE if the selected text is longer than 0 characters
return [[self selectedTextualRepresentation] length] > 0;
}

And in our performMyAction method we show an UIAlertView:

- (void)performMyAction {

//get the selected text
NSString *selection = [self selectedTextualRepresentation];

UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Selected Text" 
                                                          message:selection delegate:nil 
                                                          cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[av show]; //shows the alert
[av release]; //releases the object to avoid memory leaks

}

To sum it up, +(void)load registers our Action Menu Item to be shown in the UIMenuController, - (BOOL)canPerformAction checks if there is any selected text, and - (void)performMyAction will run our code when the menu item is selected.

This is everything you need to know for your first Action Menu Plugin. All you need to do is change the actions that take place in the performMyAction method and you can customize your plugin.

External links