InIOS systemUsed inStatic Link LibraryIs the content to be introduced in this article, mainly to understand and learnIOS systemMediumStatic Link LibraryFor more information, see this article.
1. Develop a static Link Library for iOS
Open XCode to create a project, select "CocoaTouchStaticLibrary" under the Library, and name it "EncryptLibrary ". This newly createdStaticIn the library project, there are no program files except "EncryptLibrary_Prefix.pch". Right-click the Classes folder and choose "NewFile ...", Select "Objective-Cclass" under "CocoaTouchClass" and name the source file "Encrypt. m ", and select generate Encrypt. h header file. You can see that Encrypt is generated under the Classes directory. h and Encrypt. m file. Enter the following content in the Encrypt. h header file:
- #import
- @interfaceEncrypt:NSObject{
- }
// Encode the plaintext user name and password and return the encoded string
- +(NSString*)EncryptUserNameAndPassword:(NSString*)strUserNamePassword:(NSString*)strPassword;
- @end
The content of the implementation file Encrypt. m is as follows:
- #import"Encrypt.h"
- @implementationEncrypt
- +(NSString*)EncryptUserNameAndPassword:(NSString*)strUserNamePassword:(NSString*)strPassword
- {
- NSString*strEncrypted=[NSStringstringWithFormat:@"UserName:%@,Password:%@",strUserName,strPassword];
- ReturnstrEncrypted;
- }
- @end
Here we provide a function to encode the plaintext user name and password. So far, this static function library has been compiled. Compile this program and you will see a static library file named "libEncryptLibrary. a" is generated under the Products directory.
2. Create a static link library developed in the Project Test
Create a new "Window-basedApplication" project and name it "EncryptLibraryTest". The following shows how to use the previously generated static library libEncryptLibrary. a file in the new project.
First open the Finder and translate the libEncryptLibrary generated above. copy file a to EncryptLibraryTest. xcodeproj directory of the same level, Encrypt. copy h to EncryptLibraryTest. under the Classes folder in the same directory of xcodeproj, right-click Frameworks> Add> ExistingFiles in Xcode .. add the copied libEncryptLibrary. file a, and then use the functions in the static library as follows:
- #import
- #import"Encrypt.h"
- @interfaceEncryptLibraryTestAppDelegate:NSObject{
- UIWindow*window;
- }
- @property(nonatomic,retain)IBOutletUIWindow*window;
- @end
Modify the implementation file as follows:
- #import"EncryptLibraryTestAppDelegate.h"
- @implementationEncryptLibraryTestAppDelegate
- @synthesizewindow;
- -(BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions{
- //Overridepointforcustomizationafterapplaunch.
- [self.windowaddSubview:viewController.view];
- [self.windowmakeKeyAndVisible];
- NSString*strUserName=@”caijinhui”;
- NSString*strPassWord=@”password”;
- NSString*strEncrypted=[EncryptEncryptUserNameAndPassword:strUserNamePassword:strPassWord];
- NSLog(@”%@”,strEncrypted);
- returnYES;
- }
- -(void)dealloc{
- [windowrelease];
- [superdealloc];
- }
- @end
Compile the code and pass it smoothly. The encoded string is output on the Console.
Tip: Because this document is written in Office2007, opening it in a text editor on Mac will result in abnormal Department characters, especially double quotation marks in the program. If compilation fails, please change the double quotation marks.
Summary: InIOS systemUsed inStatic Link LibraryThe contentIOS systemMediumLink LibraryThe learning of application content is helpful to you.