Use of THEOS % new

Source: Internet
Author: User

Today, I checked the logos of THEOS, and added a common sign "% new" to the hook class to add new functions. For example, we want to implement the delegate method of a class for springboard. The simplest thing is to let the springboard implement the alert proxy method so that the corresponding response can be made after clicking the button.

Step 1: Let springboard implement the delegate method.

# Import<Springboard/Springboard. h>

@ InterfaceSpringboard () <uialertviewdelegate>

@ End

Everyone knows this role.

 

The second step is to add the implementation of the alert proxy method to the springboard.

% Hook springboard

 

%New(V @: @ I)

-(Void) Alertview :( uialertview *) Av clickedbuttonatindex :( nsinteger) buttonindex

{

If(Av. Tag! =10010)

{

Nslog (@ "Av. Tag! = 10010");

Return;

}

BoolRes = [[uiapplication sharedapplication] canopenurl: [nsurl urlwithstring:@ Http://www.126.com"];

If(RES ){

Nslog (@ "Open myapptest ://");

[[Uiapplication sharedapplication] Openurl: [nsurl urlwithstring:@ Http://www.126.com"];

}

 

}

% End

 

Here we will focus on the usage of % new.

A reply from a foreign website

All objective-C methods take at least two arguments, one of Type 'id', the other of Type 'sel '. these arguments are 'implicit', in that they are not explicitly declared by the programmer. the first is named 'self '(the object processing the message) and the other is' _ cmd', the selector for the sent message.

 

@ = ID

: = Sel

 

V @: =-/+ (void) Method

V @: @ =-/+ (void) methodwithobjectid :( ID) OBJ

 

V represents the return type void @ representing an objc object: Representing sel;

I Represents the int type

For more information about the specific symbols, see objective-C runtime programming guide (objective-C runtime programming guide)

Http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html

 

The complete image of the previous simple demo. The environment is iosopendev.

This demo is implemented. After the instance is started, a dialog box pops up. After you click thanks, the page will jump to the 126 mailbox homepage.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.