第一天
一、 RNCryptor加密库导入
打算项目内使用RNCryptor加密,AES加密方式
Github地址:RNCryptor
Objective-C版本地址:RNCryptor-objc
clone地址:https://github.com/RNCryptor/RNCryptor-objc.git
克隆到本地后,将RNCryptor和RNCryptor iOS文件夹导入到工程中。
使用 需要在Build Phases的Link Binary With Libraries中添加Security.framework
RNCryptor iOS.h文件中,需要将
#import <RNCryptor/RNCryptor.h">
#import <RNCryptor/RNDecryptor.h>
#import <RNCryptor/RNEncryptor.h>
#import <RNCryptor/RNCryptorEngine.h>
改为
#import "RNCryptor.h"
#import "RNDecryptor.h"
#import "RNEncryptor.h"
#import "RNCryptorEngine.h"
才可以正常编译。编译成功后,在需要使用的地方#import "RNCryptor iOS.h"即可。
#RNCryptor的使用
NSData *data = [NSData data];//获得需要加密的数据
NSSring *privateKey = @"123456";
NSError *error;
//RNCryptor加密
NSData *encryptedData = [RNEncryptor encryptData:data withSettings:kRNCryptorAES256Settings password: privateKey error:&error];
//RNCryptor解密
NSData *decryptedData = [RNDecryptor decryptData:encryptedData withSettings:kRNCryptorAES256Settings password: privateKey error:&error];
MyLog(@"%@",decryptedData);
2.国际化
Command+N在工程内新建一个StringsFile文件
再到Projrct中,选择Info,在Localization中添加需要的语言。
回到文件列表,选中该文件,如Localized.strings,打开Xcode右边区域,查看该文件详情,找到“Localization”,选中需要的语言,然后Localized.strings下会自动生成对应的国际化文件。
使用国际化时,用NSLocalizedString(<#key#>, <#comment#>)来获取项目中使用的字符串。
如果需要跟随系统语言,则要在Info.plist文件中添加Application has localized display name,并设置为YES
注:Info.plist中的国际化,对StringsFile的命名只能是InfoPlist.strings
3.关于#import头文件不自动提示的问题
Xcode->File->Project Setting中设置BuildSystem为:
4.App框架构建
采用常见的TabbarController上包含多个NavigationViewController的方式。
整体结构为:
UIWindow{
UITabbarController{//RootViewController
UINavigationViewController{LeonMainPageVC}
UINavigationViewController{LeonSettingVC}
UINavigationViewController{......}
......
}
}
RootViewController : UITabBarController
BaseViewController : UIViewController
LeonMainPageVC : BaseViewController
LeonSettingVC : BaseViewController
AppDelegate.m中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// 创建Window
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// 设置Window的背景颜色
self.window.backgroundColor = [UIColor whiteColor];
// 创建根控制器
_rootVC = [[RootViewController alloc] init];
// 设置根控制器
self.window.rootViewController = _rootVC;
// 设置并显示主窗口
[self.window makeKeyAndVisible];
// 监听截屏事件
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenShootAction:) name:UIApplicationUserDidTakeScreenshotNotification object:nil];
return YES;
}
RootViewController.m中
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
LeonMainPageVC *mainVC=[[LeonMainPageVC alloc] init];
LeonSettingVC *settingVC=[[LeonSettingVC alloc] init];
UINavigationController *mainNV = [[UINavigationController alloc] initWithRootViewController:mainVC];
UINavigationController *settingNV = [[UINavigationController alloc] initWithRootViewController:settingVC];
// 把子控制器添加到UITabBarController
self.viewControllers = @[mainNV, settingNV];
}
5.SourceTree配置iOS工程忽略文件
全局配置:
SourceTree->Preferences->Git->EditFile
项目独立配置:
进入相应的Repository->Setting->Advanced->Edit
在Edit文件中粘贴下方忽略规则。(iOS专用)
#project
#ProjectPath/tools/localization/xlsx
Index/
.DS_Store
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## Build generated
build/
DerivedData/
## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint
## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM
*.log
# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts
Carthage/Build
# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output
# Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode
iOSInjectionProject/
#GULP
node_modules/
package-lock.json