├── .gitattributes
├── .gitignore
├── CodeSnippets
├── 021B0A12-487C-4417-A291-E6FB9EA3B28A.codesnippet
├── 0D545B7E-FA77-4F60-A01A-C5DC03368099.codesnippet
├── 0F12A84D-E6FE-4C19-81CB-EA0E4BD60A20.codesnippet
├── 12F1F472-93F1-4AC3-867C-091E7CD4C428.codesnippet
├── 1BCA6BF2-3D81-4338-AB15-56A2D3B2B9DA.codesnippet
├── 1C071233-5D65-4101-9C7C-A43509BB57B8.codesnippet
├── 1C5C6C1E-D1EE-4BB7-8421-42D3ED461D3A.codesnippet
├── 32B2B107-927E-489C-A102-A413025B2B0D.codesnippet
├── 3A36211B-66E0-42EE-937A-A77DB6B61056.codesnippet
├── 4153CD73-5499-4668-B452-128583FC6848.codesnippet
├── 45D5535E-44FA-491F-8E4B-3251A46D5372.codesnippet
├── 48DE1D79-02B2-47AC-9046-25DD6AF3ED6D.codesnippet
├── 49CE67B3-4A9B-42EC-A77F-82DD89D7C83B.codesnippet
├── 5115E1AD-30E1-4CFC-B88C-4716FD620548.codesnippet
├── 524E7A76-9BBC-4442-86F2-37DB97C7AC37.codesnippet
├── 566A116E-AD32-4E7F-8157-3BDB6A33AF35.codesnippet
├── 56EEC983-67DA-4B03-82DE-D3BFC24B8FC1.codesnippet
├── 6285E386-3B66-4C86-A176-D4E2C3749148.codesnippet
├── 6773DBE1-3F3C-4F8A-B5FA-B3B65826DD70.codesnippet
├── 75CBC3C4-E06B-4EA5-9CB9-2355EFF782A5.codesnippet
├── 7707FE2A-C6CF-4774-8A7D-EA6BEE058C11.codesnippet
├── 7E58673D-D816-4B12-994E-89ACB0EC4EFF.codesnippet
├── 84587A91-678A-4727-9EBA-6F9D327EF485.codesnippet
├── 8463A667-951C-46F7-840D-EACC85C27B3C.codesnippet
├── 853A4378-0888-45EF-85DB-10A9427E860E.codesnippet
├── 872BFC2F-2F1F-48BE-AD9F-06B89D76C861.codesnippet
├── 8D68DFE7-69E7-46E6-B4F0-F3C5EEC1BC12.codesnippet
├── 8DC1C3D8-F7DD-4D73-8C58-9A8D8538DD6D.codesnippet
├── 93934053-BDF5-48C3-8B7F-08EB04D69442.codesnippet
├── A22A7D0A-8EC9-4A4C-AD7C-F2A46D31FCCD.codesnippet
├── A807145A-F6BD-412C-AA06-DC931E43F730.codesnippet
├── A83AE4CD-E79A-464F-B849-29BEB3CF4B01.codesnippet
├── B9E1ED5F-F3D6-4479-A2DF-0C8B21740CD6.codesnippet
├── BC5A4D5B-EA3A-4B57-AC87-436F2A48D938.codesnippet
├── BE20F1E7-4C7D-481D-9D8D-8CA1DB1F803E.codesnippet
├── CF7257F4-1089-42C5-82E7-6A956C9F702B.codesnippet
├── D1E528DB-F1FA-4A8A-8ABF-11391DEFE535.codesnippet
├── E10BEAE2-7433-4892-9314-95759F276395.codesnippet
├── E1DCA19E-0BD3-4CF5-BFEA-16327ACBC64C.codesnippet
├── E4A6DA59-C865-44F9-9BB3-5A946BE0B157.codesnippet
├── E69F93F9-C828-443E-A2D6-C0AB47FE54AA.codesnippet
├── F2945E28-8E0F-4E27-8840-F40C4E7E7E5D.codesnippet
├── F95F0606-30C9-41A8-9732-6D055E009DF0.codesnippet
└── FE25181C-41FC-436A-B948-6ADE2961E4FE.codesnippet
├── IAP
├── RNCryptor
│ ├── include
│ │ ├── RNCryptor+Private.h
│ │ ├── RNCryptor.h
│ │ ├── RNCryptorEngine.h
│ │ ├── RNDecryptor.h
│ │ └── RNEncryptor.h
│ └── libRNCryptor.a
├── Security
│ ├── .svn
│ │ ├── entries
│ │ ├── format
│ │ ├── pristine
│ │ │ ├── 14
│ │ │ │ └── 144b7746ff05b8c87d60061591b55e5f70d039dd.svn-base
│ │ │ ├── 19
│ │ │ │ └── 19ef1c9db6c786a82e30b58be473170360ed3719.svn-base
│ │ │ ├── 59
│ │ │ │ └── 59ae2cd489f0ae59d554a6992cdb6e8d4fe106fb.svn-base
│ │ │ ├── 2c
│ │ │ │ └── 2c099529c402e61ac13c440b6792e13361c84c20.svn-base
│ │ │ ├── 3b
│ │ │ │ └── 3b8cc33d1218668dc0cc108077dce356941a9858.svn-base
│ │ │ └── fb
│ │ │ │ └── fbd022ba7ee80f72f3b7ae8fd6c55b53d5bd9c75.svn-base
│ │ └── wc.db
│ ├── GTMBase64
│ │ ├── GTMBase64.h
│ │ ├── GTMBase64.m
│ │ └── GTMDefines.h
│ ├── NSData+AES.h
│ ├── NSData+AES.m
│ ├── SecurityUtil.h
│ └── SecurityUtil.m
├── YYStoreKitManager.h
└── YYStoreKitManager.m
├── LICENSE
├── README.md
├── clear_Temp_data.sh
├── clear_snippets.sh
├── open_CodeSnippets.sh
├── result.png
└── setup_snippets.sh
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.sh linguist-language=objective-c
2 | *.codesnippet linguist-language=objective-c
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | #
3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4 |
5 | ## Build generated
6 | build/
7 | DerivedData/
8 |
9 | ## Various settings
10 | *.pbxuser
11 | !default.pbxuser
12 | *.mode1v3
13 | !default.mode1v3
14 | *.mode2v3
15 | !default.mode2v3
16 | *.perspectivev3
17 | !default.perspectivev3
18 | xcuserdata/
19 |
20 | ## Other
21 | *.moved-aside
22 | *.xccheckout
23 | *.xcscmblueprint
24 |
25 | ## Obj-C/Swift specific
26 | *.hmap
27 | *.ipa
28 | *.dSYM.zip
29 | *.dSYM
30 |
31 | # CocoaPods
32 | #
33 | # We recommend against adding the Pods directory to your .gitignore. However
34 | # you should judge for yourself, the pros and cons are mentioned at:
35 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
36 | #
37 | # Pods/
38 |
39 | # Carthage
40 | #
41 | # Add this line if you want to avoid checking in source code from Carthage dependencies.
42 | # Carthage/Checkouts
43 |
44 | Carthage/Build
45 |
46 | # fastlane
47 | #
48 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
49 | # screenshots whenever they are needed.
50 | # For more information about the recommended setup visit:
51 | # https://docs.fastlane.tools/best-practices/source-control/#source-control
52 |
53 | fastlane/report.xml
54 | fastlane/Preview.html
55 | fastlane/screenshots
56 | fastlane/test_output
57 |
58 | # Code Injection
59 | #
60 | # After new code Injection tools there's a generated folder /iOSInjectionProject
61 | # https://github.com/johnno1962/injectionforxcode
62 |
63 | iOSInjectionProject/
64 |
--------------------------------------------------------------------------------
/CodeSnippets/021B0A12-487C-4417-A291-E6FB9EA3B28A.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY TextField
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | UITextField*textField = [[UITextField alloc]initWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)];
13 | textField.placeholder = <#placeholder#>;
14 | textField.textAlignment = <#NSTextAlignment + esc#>;
15 | textField.secureTextEntry = <#bool#>; //是否密文输入
16 | //textField.borderStyle = UITextBorderStyleLine;
17 | textField.keyboardType = UIKeyboardTypeEmailAddress; //键盘类型
18 | textField.autocapitalizationType = NO; //关闭首字母大写
19 | textField.clearButtonMode = YES; //清除按钮
20 | textField.leftView = <#imageView#>;
21 | textField.leftViewMode = UITextFieldViewModeAlways;
22 | textField.rightView = <#rightImageView#>;
23 | textField.rightViewMode = UITextFieldViewModeWhileEditing; //编辑状态下一直存在
24 | //textField.inputView //自定义键盘
25 | textField.font = [UIFont systemFontOfSize:<#font#>];
26 | textField.textColor = <#UIColor#>;
27 | //自定义清除按键img
28 | UIButton *button = [textField valueForKey:@"_clearButton"];
29 | [button setImage:[UIImage imageNamed:@"shanchu"] forState:UIControlStateNormal];
30 | textField.clearButtonMode = UITextFieldViewModeWhileEditing;
31 | [<#superView#> addSubview:textField];
32 | IDECodeSnippetIdentifier
33 | 021B0A12-487C-4417-A291-E6FB9EA3B28A
34 | IDECodeSnippetLanguage
35 | Xcode.SourceCodeLanguage.Objective-C
36 | IDECodeSnippetSummary
37 | 一键创建 UITextField 自定义清除按键img
38 | IDECodeSnippetTitle
39 | UITextField
40 | IDECodeSnippetUserSnippet
41 |
42 | IDECodeSnippetVersion
43 | 2
44 |
45 |
46 |
--------------------------------------------------------------------------------
/CodeSnippets/0D545B7E-FA77-4F60-A01A-C5DC03368099.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY Timer
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | NSTimer *<#timerName#> = [NSTimer timerWithTimeInterval:<#CGFloat_sec#> target:self selector:@selector(<#selector#>) userInfo:nil repeats:YES];
13 | /** 解决 滚动视图滚动的时候 timer暂停的问题 */
14 | [[NSRunLoop currentRunLoop] addTimer:<#timerName#> forMode:NSRunLoopCommonModes];
15 |
16 | /** 移除 */
17 | [<#timerName#> invalidate];
18 | <#timerName#> = nil;
19 |
20 | /** 开启timer (可以先移除再创建timer)*/
21 | if (<#timerName#> == nil) {
22 | //重新创建
23 | }
24 | IDECodeSnippetIdentifier
25 | 0D545B7E-FA77-4F60-A01A-C5DC03368099
26 | IDECodeSnippetLanguage
27 | Xcode.SourceCodeLanguage.Objective-C
28 | IDECodeSnippetSummary
29 | 一键创建 计时器 暂停 和 开始
30 | IDECodeSnippetTitle
31 | NSTimer
32 | IDECodeSnippetUserSnippet
33 |
34 | IDECodeSnippetVersion
35 | 2
36 |
37 |
38 |
--------------------------------------------------------------------------------
/CodeSnippets/0F12A84D-E6FE-4C19-81CB-EA0E4BD60A20.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY AFN_Download
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
13 | //设置超时时间
14 | manager.requestSerializer.timeoutInterval = 15.0f;
15 | //manager.requestSerializer = [AFJSONRequestSerializer serializer];
16 | //manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
17 |
18 | NSURL *url = [NSURL URLWithString:@""];
19 | NSURLRequest *request = [NSURLRequest requestWithURL:url];
20 | NSURLSessionDownloadTask *downloadtask = [manager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {
21 | //打印下载进度
22 | NSLog(@"%lf",1.0 * downloadProgress.completedUnitCount / downloadProgress.totalUnitCount);
23 | } destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
24 | //设置存储路径
25 | NSString *filePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
26 | return [NSURL fileURLWithPath:[filePath stringByAppendingPathComponent:response.suggestedFilename]];
27 | } completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
28 | //下载完成的回调
29 | NSLog(@"下载完成");
30 | NSLog(@"%@--%@",response,filePath);
31 | }];
32 | [downloadtask resume];
33 | IDECodeSnippetIdentifier
34 | 0F12A84D-E6FE-4C19-81CB-EA0E4BD60A20
35 | IDECodeSnippetLanguage
36 | Xcode.SourceCodeLanguage.Objective-C
37 | IDECodeSnippetSummary
38 | 利用AFNetworking 一键下载 带 进度
39 | IDECodeSnippetTitle
40 | AFNetworking download下载 带 进度
41 | IDECodeSnippetUserSnippet
42 |
43 | IDECodeSnippetVersion
44 | 0
45 |
46 |
47 |
--------------------------------------------------------------------------------
/CodeSnippets/12F1F472-93F1-4AC3-867C-091E7CD4C428.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY TableView
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | <UITableViewDelegate, UITableViewDataSource>
13 |
14 | @property (nonatomic, strong) UITableView *tableView;
15 |
16 | /** 几个分区 */
17 | -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
18 |
19 | return <#expression#>;
20 | }
21 | /** 每个分区多少行 */
22 | -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
23 |
24 | return <#expression#>;
25 | }
26 | /** 每一行 */
27 | -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
28 |
29 | return <#expression#>;
30 | }
31 | /** 点击每一行 action */
32 | -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
33 |
34 | }
35 | /** 每一行高度 */
36 | -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
37 | return <#expression#>;
38 | }
39 |
40 | /** lazy */
41 | -(UITableView *)tableView {
42 | if (_tableView == nil) {
43 | _tableView = [[UITableView alloc] initWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>) style:<#UITableViewStyle#>]
44 | _tableView.dataSource = self;
45 | _tableView.delegate = self;
46 | [<#superview#> addSubview:_tableView];
47 | }
48 | }
49 |
50 | IDECodeSnippetIdentifier
51 | 12F1F472-93F1-4AC3-867C-091E7CD4C428
52 | IDECodeSnippetLanguage
53 | Xcode.SourceCodeLanguage.Objective-C
54 | IDECodeSnippetSummary
55 | 一键 创建 UITableView delegate/DataSource method
56 | IDECodeSnippetTitle
57 | UITableView
58 | IDECodeSnippetUserSnippet
59 |
60 | IDECodeSnippetVersion
61 | 2
62 |
63 |
64 |
--------------------------------------------------------------------------------
/CodeSnippets/1BCA6BF2-3D81-4338-AB15-56A2D3B2B9DA.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY ImageView
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | UIImageView*imageView=[[UIImageView alloc]initWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)];
13 | imageView.image= <#imageName#>;
14 | //圆角
15 | imageView.layer.masksToBounds = YES;
16 | imageView.layer.cornerRadius = <#CGFloat#>; //圆角
17 |
18 | //边框
19 | imageView.layer.borderWidth = <#CGFloat#>; //边框宽度
20 | imageView.layer.borderColor = <#UIColor#>.CGColor; //边框颜色
21 |
22 | //打开用户交互 UIImageView的用户交互是默认处于关闭状态的
23 | //imageView.userInteractionEnabled=YES;
24 |
25 | //使图片保持原样不压缩
26 | //imageView.contentMode = UIViewContentModeScaleAspectFill ;
27 |
28 | //剪切图片 按imageView的大小
29 | //imageView.clipsToBounds = YES ;
30 |
31 | //让图片用原色显示 image
32 | // image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] ;
33 | [<#superView#> addSubview:imageView];
34 | IDECodeSnippetIdentifier
35 | 1BCA6BF2-3D81-4338-AB15-56A2D3B2B9DA
36 | IDECodeSnippetLanguage
37 | Xcode.SourceCodeLanguage.Objective-C
38 | IDECodeSnippetSummary
39 | 一键创建 UIImageView
40 | IDECodeSnippetTitle
41 | UIImageView
42 | IDECodeSnippetUserSnippet
43 |
44 | IDECodeSnippetVersion
45 | 2
46 |
47 |
48 |
--------------------------------------------------------------------------------
/CodeSnippets/1C071233-5D65-4101-9C7C-A43509BB57B8.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY custom_dispatch
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | dispatch_queue_t urls_queue = dispatch_queue_create("com.elctech.image_queue", NULL);
13 |
14 | dispatch_async(urls_queue, ^{
15 | [self getImageUrls];
16 | dispatch_async(dispatch_get_main_queue(), ^{
17 | [self downloadImages];
18 | });
19 | });
20 |
21 | dispatch_release(urls_queue);
22 | IDECodeSnippetIdentifier
23 | 1C071233-5D65-4101-9C7C-A43509BB57B8
24 | IDECodeSnippetLanguage
25 | Xcode.SourceCodeLanguage.Objective-C
26 | IDECodeSnippetSummary
27 | Custom dispatch queue
28 | IDECodeSnippetTitle
29 | Custom dispatch queue
30 | IDECodeSnippetUserSnippet
31 |
32 | IDECodeSnippetVersion
33 | 2
34 |
35 |
36 |
--------------------------------------------------------------------------------
/CodeSnippets/1C5C6C1E-D1EE-4BB7-8421-42D3ED461D3A.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY Swich
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | //不能设置大小 只能设置位置
13 | UISwitch *switc = [[UISwitch alloc]initWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)];
14 | //添加触发事件
15 | [switc addTarget:self action:@selector(<#selector#>:) forControlEvents:UIControlEventValueChanged];
16 | //设置初始状态
17 | switc.on = NO ;
18 | [<#superView#> addSubview:switc];
19 |
20 | //点击事件
21 | -(void) <#selector#>:(UISwitch *) switc {
22 |
23 | if (switc.on == YES) {
24 | NSLog(@"开关被打开") ;
25 | } else {
26 | NSLog(@"开关被关闭") ;
27 | }
28 | }
29 |
30 | IDECodeSnippetIdentifier
31 | 1C5C6C1E-D1EE-4BB7-8421-42D3ED461D3A
32 | IDECodeSnippetLanguage
33 | Xcode.SourceCodeLanguage.Objective-C
34 | IDECodeSnippetSummary
35 | 一键创建Switch 附带点击事件 action
36 | IDECodeSnippetTitle
37 | UISwitch
38 | IDECodeSnippetUserSnippet
39 |
40 | IDECodeSnippetVersion
41 | 0
42 |
43 |
44 |
--------------------------------------------------------------------------------
/CodeSnippets/32B2B107-927E-489C-A102-A413025B2B0D.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY AlertControllerUserNamePwdTextField
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | // @property (nonatomic, strong) UITextField *nameTextfield;
13 | // @property (nonatomic, strong) UITextField *pwdTextfield;
14 | UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:<#标题#> message:<#描述#> preferredStyle:UIAlertControllerStyleAlert];
15 | UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消"style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
16 |
17 | NSLog(@" 取消按键被点击 用户名:%@ 密码: %@",self.nameTextfield.text,self.pwdTextfield.text);
18 | }];
19 | UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定"style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
20 | NSLog(@" 确定按键被点击 用户名:%@ 密码: %@",self.nameTextfield.text,self.pwdTextfield.text);
21 | }];
22 | __weak typeof (self) weakSelf = self;
23 | [alertVc addTextFieldWithConfigurationHandler:^(UITextField*textField){
24 |
25 | textField.placeholder = @"用户名";
26 |
27 | textField.secureTextEntry = NO;
28 | weakSelf.nameTextfield = textField;
29 |
30 | }];
31 | [alertVc addTextFieldWithConfigurationHandler:^(UITextField*textField){
32 |
33 | textField.placeholder = @"密码";
34 |
35 | textField.secureTextEntry = YES;
36 | weakSelf.pwdTextfield = textField;
37 | }];
38 | [alertVc addAction:cancelAction];
39 | [alertVc addAction:sureAction];
40 | [self presentViewController:alertVc animated:YES completion:^{ }];
41 | IDECodeSnippetIdentifier
42 | 32B2B107-927E-489C-A102-A413025B2B0D
43 | IDECodeSnippetLanguage
44 | Xcode.SourceCodeLanguage.Objective-C
45 | IDECodeSnippetSummary
46 | 一键创建 UIAlertController 附带userName/PwdTextField
47 | IDECodeSnippetTitle
48 | UIAlertController userName userPassword
49 | IDECodeSnippetUserSnippet
50 |
51 | IDECodeSnippetVersion
52 | 0
53 |
54 |
55 |
--------------------------------------------------------------------------------
/CodeSnippets/3A36211B-66E0-42EE-937A-A77DB6B61056.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY Pay_IAP
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | //#import "YYStoreKitManager.h"
13 | //需要在苹果后台添加内购项目, 并添加沙箱测试员账号
14 | //测试时, 先到手机设置里面将 iTunes Store 与 AppStore 已经登录的正式环境的账号退出(注销),提示:这里不能登录沙箱测试账号
15 | //直接执行下面两句代码 然后使用现有账号, 登录沙箱测试账号就可以购买成功了.
16 | [[YYStoreKitManager sharedInstance] initialStore];
17 | [[YYStoreKitManager sharedInstance] buy:@"产品ID"];
18 | IDECodeSnippetIdentifier
19 | 3A36211B-66E0-42EE-937A-A77DB6B61056
20 | IDECodeSnippetLanguage
21 | Xcode.SourceCodeLanguage.Objective-C
22 | IDECodeSnippetSummary
23 | 一键 苹果支付 (IAP,In App Purchases 应用内支付)
24 | IDECodeSnippetTitle
25 | IAP
26 | IDECodeSnippetUserSnippet
27 |
28 | IDECodeSnippetVersion
29 | 0
30 |
31 |
32 |
--------------------------------------------------------------------------------
/CodeSnippets/4153CD73-5499-4668-B452-128583FC6848.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY Mark
7 | IDECodeSnippetCompletionScopes
8 |
9 | All
10 |
11 | IDECodeSnippetContents
12 | #pragma mark - <#Label#>
13 | IDECodeSnippetIdentifier
14 | 4153CD73-5499-4668-B452-128583FC6848
15 | IDECodeSnippetLanguage
16 | Xcode.SourceCodeLanguage.Objective-C
17 | IDECodeSnippetSummary
18 | 一键 mark
19 | IDECodeSnippetTitle
20 | Pragma mark
21 | IDECodeSnippetUserSnippet
22 |
23 | IDECodeSnippetVersion
24 | 2
25 |
26 |
27 |
--------------------------------------------------------------------------------
/CodeSnippets/45D5535E-44FA-491F-8E4B-3251A46D5372.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY dispatch_once_t
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassImplementation
10 |
11 | IDECodeSnippetContents
12 | + (instancetype)sharedInstance
13 | {
14 | static id sharedInstance = nil;
15 | static dispatch_once_t onceToken;
16 | dispatch_once(&onceToken, ^{
17 | sharedInstance = [[self alloc] init];
18 | });
19 | return sharedInstance;
20 | }
21 | IDECodeSnippetIdentifier
22 | 45D5535E-44FA-491F-8E4B-3251A46D5372
23 | IDECodeSnippetLanguage
24 | Xcode.SourceCodeLanguage.Objective-C
25 | IDECodeSnippetSummary
26 | dispatch_once_t
27 | IDECodeSnippetTitle
28 | dispatch_once_t
29 | IDECodeSnippetUserSnippet
30 |
31 | IDECodeSnippetVersion
32 | 2
33 |
34 |
35 |
--------------------------------------------------------------------------------
/CodeSnippets/48DE1D79-02B2-47AC-9046-25DD6AF3ED6D.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY ///
7 | IDECodeSnippetCompletionScopes
8 |
9 | All
10 |
11 | IDECodeSnippetContents
12 | /**
13 | *
14 | */
15 | IDECodeSnippetIdentifier
16 | 48DE1D79-02B2-47AC-9046-25DD6AF3ED6D
17 | IDECodeSnippetLanguage
18 | Xcode.SourceCodeLanguage.Objective-C
19 | IDECodeSnippetSummary
20 | 多行注释
21 | IDECodeSnippetTitle
22 | /// 注释
23 | IDECodeSnippetUserSnippet
24 |
25 | IDECodeSnippetVersion
26 | 2
27 |
28 |
29 |
--------------------------------------------------------------------------------
/CodeSnippets/49CE67B3-4A9B-42EC-A77F-82DD89D7C83B.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY PlayMusic
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassImplementation
10 |
11 | IDECodeSnippetContents
12 | #import <AVFoundation/AVFoundation.h>
13 | -(void)playAudioPlayerWithString:(NSString*)name delegate:(id)delegate
14 | {
15 | NSString *urlStr=[[NSBundle mainBundle]pathForResource:name ofType:nil];
16 | NSURL *url=[NSURL fileURLWithPath:urlStr];
17 | NSError *error=nil;
18 | AVAudioPlayer *audioPlayer=[[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error];
19 | //设置播放器属性
20 | audioPlayer.numberOfLoops=0;//设置为0不循环 MAXFLOAT一直重复
21 | audioPlayer.delegate=delegate;
22 | [audioPlayer prepareToPlay];//加载音频文件到缓存
23 | if(error){
24 | NSLog(@"初始化播放器过程发生错误,错误信息:%@",error.localizedDescription);
25 | }
26 | }
27 | IDECodeSnippetIdentifier
28 | 49CE67B3-4A9B-42EC-A77F-82DD89D7C83B
29 | IDECodeSnippetLanguage
30 | Xcode.SourceCodeLanguage.Objective-C
31 | IDECodeSnippetSummary
32 | 一键播放音频文件
33 | IDECodeSnippetTitle
34 | AVAudioPlayer
35 | IDECodeSnippetUserSnippet
36 |
37 | IDECodeSnippetVersion
38 | 0
39 |
40 |
41 |
--------------------------------------------------------------------------------
/CodeSnippets/5115E1AD-30E1-4CFC-B88C-4716FD620548.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY PCH
7 | IDECodeSnippetCompletionScopes
8 |
9 | TopLevel
10 |
11 | IDECodeSnippetContents
12 |
13 | #pragma mark - ==================== 头文件
14 | #import <UIKit/UIKit.h>
15 | #import <Foundation/Foundation.h>
16 |
17 |
18 | #pragma mark - ==================== 强弱self
19 | #define kWeakSelf(weakSelf) __weak __typeof(&*self)weakSelf = self;
20 | #define kStrongSelf(strongSelf) __strong __typeof(&*self)strongSelf = self;
21 |
22 | #pragma mark - ==================== log
23 | #ifdef DEBUG //打印控制器名称 方法名称 所在行数
24 | # define SSLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
25 | #else
26 | # define SSLog(...)
27 | #endif
28 |
29 | #pragma mark - ==================== frame font
30 | //frame
31 | #define ONE_PX 1/[[UIScreen mainScreen] scale]
32 | #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
33 | #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
34 | #define SCREEN_BOUNDS [UIScreen mainScreen].bounds
35 | //font
36 | #define kFont(x) [UIFont systemFontOfSize:x]
37 | #define kBoldFont(x) [UIFont boldSystemFontOfSize:x]
38 | //程序的本地化,引用国际化的文件
39 | #define MyLocal(x, ...) NSLocalizedString(x, nil)
40 |
41 |
42 | #pragma mark - ==================== getSysMessage
43 | //获取系统版本 SSLog(@"%.1lf",kCurrentSystemVersion); //保留几位小数
44 | #define kCurrentSystemVersion [[[UIDevice currentDevice] systemVersion] floatValue]
45 | //获取当前语言
46 | #define kCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
47 | #define IOS7 ([[UIDevice currentDevice].systemVersion doubleValue] >= 7.0]
48 | #define IOS8 ([[UIDevice currentDevice].systemVersion doubleValue] >= 8.0)
49 | #define iOS9 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0)
50 |
51 | #define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ?CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
52 | #define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ?CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
53 | #define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
54 |
55 | //判断是真机还是模拟器
56 | #if TARGET_OS_IPHONE
57 | //iPhone Device
58 | #endif
59 | #if TARGET_IPHONE_SIMULATOR
60 | //iPhone Simulator
61 | #endif
62 |
63 | //使用ARC和不使用ARC
64 | #if __has_feature(objc_arc)
65 | //compiling with ARC
66 | #else
67 | // compiling without ARC
68 | #endif
69 |
70 |
71 |
72 | #pragma mark - ==================== image color
73 | //定义UIImage对象
74 | #define kImageNamed(_pointer) [UIImage imageNamed:[UIUtil imageName:_pointer]]
75 | #define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
76 | #define colorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
77 | #define kClearColor [UIColor clearColor]
78 |
79 | //带有RGBA的颜色设置
80 | #define colorWithR_G_B(R, G, B, A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]
81 | //生成一个随机颜色
82 | #define random(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)/255.0]
83 | #define randomColor random(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))
84 |
85 |
86 |
87 |
88 | #pragma mark - ==================== GCD
89 | // GLOBAL_THREAD(^{ code });
90 | #define GLOBAL_THREAD(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
91 | #define MAIN_THREAD(block) dispatch_async(dispatch_get_main_queue(),block)
92 |
93 |
94 | #pragma mark - ==================== 通知中心
95 | #define kNotificationCenter [NSNotificationCenter defaultCenter]
96 |
97 |
98 | #pragma mark - ==================== 文件管理相关
99 | #define kUserDefault [NSUserDefaults standardUserDefaults] //userDefault
100 | #define kFileManager [NSFileManager defaultManager] //fileManager
101 | #define kDocmentPath NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject
102 |
103 | #pragma mark - ==================== 单例一个类
104 | // .h
105 | #define singleton_interface(class) + (instancetype)shared##class;
106 | // .m
107 | #define singleton_implementation(class) \
108 | static class *_instance; \
109 | \
110 | + (id)allocWithZone:(struct _NSZone *)zone \
111 | { \
112 | static dispatch_once_t onceToken; \
113 | dispatch_once(&onceToken, ^{ \
114 | _instance = [super allocWithZone:zone]; \
115 | }); \
116 | \
117 | return _instance; \
118 | } \
119 | \
120 | + (instancetype)shared##class \
121 | { \
122 | if (_instance == nil) { \
123 | _instance = [[class alloc] init]; \
124 | } \
125 | \
126 | return _instance; \
127 | }
128 |
129 |
130 | //由角度获取弧度 有弧度获取角度
131 | #define degreesToRadian(x) (M_PI * (x) / 180.0)
132 | #define radianToDegrees(radian) (radian*180.0)/(M_PI)
133 |
134 |
135 | IDECodeSnippetIdentifier
136 | 5115E1AD-30E1-4CFC-B88C-4716FD620548
137 | IDECodeSnippetLanguage
138 | Xcode.SourceCodeLanguage.Objective-C
139 | IDECodeSnippetSummary
140 | 一键添加常用宏
141 | IDECodeSnippetTitle
142 | PrefixHeader.pch
143 | IDECodeSnippetUserSnippet
144 |
145 | IDECodeSnippetVersion
146 | 2
147 |
148 |
149 |
--------------------------------------------------------------------------------
/CodeSnippets/524E7A76-9BBC-4442-86F2-37DB97C7AC37.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY Register_nib
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | #define ReuseIdentifier @""
13 | UINib * nib = [UINib nibWithNibName:@"" bundle:nil];
14 | [_tableView registerNib:nib forCellReuseIdentifier:ReuseIdentifier];
15 | IDECodeSnippetIdentifier
16 | 524E7A76-9BBC-4442-86F2-37DB97C7AC37
17 | IDECodeSnippetLanguage
18 | Xcode.SourceCodeLanguage.Objective-C
19 | IDECodeSnippetSummary
20 | 一键注册nib register nib
21 | IDECodeSnippetTitle
22 | register nib
23 | IDECodeSnippetUserSnippet
24 |
25 | IDECodeSnippetVersion
26 | 2
27 |
28 |
29 |
--------------------------------------------------------------------------------
/CodeSnippets/566A116E-AD32-4E7F-8157-3BDB6A33AF35.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY WebView
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)];
13 | NSURL *url = [NSURL URLWithString:<#urlString#>];
14 | NSURLRequest *requst = [NSURLRequest requestWithURL:url];
15 | [webView loadRequest:requst];
16 | webView.delegate = self;
17 | [<#someView#> addSubview:webView];
18 |
19 |
20 | #pragma mark - webViewDelegate
21 | -(void)webViewDidStartLoad:(UIWebView *)webView {
22 | NSLog(@"开始加载");
23 | }
24 | -(void)webViewDidFinishLoad:(UIWebView *)webView {
25 | NSLog(@"加载完成");
26 |
27 | }
28 | -(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
29 | NSLog(@"加载失败 %@",error);
30 | }
31 |
32 | //捕获每次打开的网页
33 | -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
34 | NSString *urlString = [[request URL] absoluteString];
35 | urlString = [urlString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
36 | NSLog(@"urlString=%@",urlString);
37 | return YES;
38 | }
39 | IDECodeSnippetIdentifier
40 | 566A116E-AD32-4E7F-8157-3BDB6A33AF35
41 | IDECodeSnippetLanguage
42 | Xcode.SourceCodeLanguage.Objective-C
43 | IDECodeSnippetSummary
44 | 一键创建UIWebView 附带Delegate
45 | IDECodeSnippetTitle
46 | UIWebView
47 | IDECodeSnippetUserSnippet
48 |
49 | IDECodeSnippetVersion
50 | 0
51 |
52 |
53 |
--------------------------------------------------------------------------------
/CodeSnippets/56EEC983-67DA-4B03-82DE-D3BFC24B8FC1.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY AFN_Upload
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassImplementation
10 |
11 | IDECodeSnippetContents
12 |
13 | /**
14 | AFN3.0上传
15 | 两种方式
16 | upload1
17 | upload2
18 |
19 | */
20 | -(void) upload1 {
21 | AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
22 | NSDictionary *dict = @{@"username":@"1234"};
23 | NSString *urlstring = @"urlstring";
24 | [manager POST:urlstring parameters:dict constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
25 | //上传文件参数
26 | UIImage *image = [UIImage imageNamed:@"123.png"];
27 | NSData *data = UIImagePNGRepresentation(image);
28 | //这个就是参数
29 | [formData appendPartWithFileData:data name:@"file" fileName:@"123.png" mimeType:@"image/png"];
30 | } progress:^(NSProgress * _Nonnull uploadProgress) {
31 | //打印上传进度
32 | NSLog(@"%lf",1.0 * uploadProgress.completedUnitCount / uploadProgress.totalUnitCount);
33 | } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
34 | NSLog(@"上传成功: %@",responseObject);
35 | } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
36 | NSLog(@"请求失败:%@",error);
37 | }];
38 |
39 | }
40 | /** 第二种是通过url来获取路径,进入沙盒或者系统相册 */
41 | -(void) upload2 {
42 | AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
43 | NSDictionary *dict = @{@"username":@"1234"};
44 | NSString *urlstring = @"urlstring";
45 |
46 | [manager POST:urlstring parameters:dict constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
47 | NSError *error;
48 | [formData appendPartWithFileURL:[NSURL fileURLWithPath:@"文件地址"] name:@"file" fileName:@"123.png" mimeType:@"application/octet-stream"error:&error];
49 |
50 |
51 | } progress:^(NSProgress * _Nonnull uploadProgress) {
52 | //打印上传进度
53 | NSLog(@"%lf",1.0 * uploadProgress.completedUnitCount / uploadProgress.totalUnitCount);
54 | } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
55 | NSLog(@"上传成功: %@",responseObject);
56 |
57 | } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
58 | NSLog(@"请求失败:%@",error);
59 | }];
60 | }
61 |
62 | IDECodeSnippetIdentifier
63 | 56EEC983-67DA-4B03-82DE-D3BFC24B8FC1
64 | IDECodeSnippetLanguage
65 | Xcode.SourceCodeLanguage.Objective-C
66 | IDECodeSnippetSummary
67 | AFNetworking 两种上传文件方式
68 | IDECodeSnippetTitle
69 | AFNetworking 两种上传文件方式
70 | IDECodeSnippetUserSnippet
71 |
72 | IDECodeSnippetVersion
73 | 0
74 |
75 |
76 |
--------------------------------------------------------------------------------
/CodeSnippets/6285E386-3B66-4C86-A176-D4E2C3749148.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY AFN_监听网络状态,网络改变触发回调
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | //#import <AFNetworking/AFNetworking.h>
13 | AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
14 |
15 | /*枚举里面四个状态 分别对应 未知 无网络 数据 WiFi
16 | typedef NS_ENUM(NSInteger, AFNetworkReachabilityStatus) {
17 | AFNetworkReachabilityStatusUnknown = -1, 未知
18 | AFNetworkReachabilityStatusNotReachable = 0, 无网络
19 | AFNetworkReachabilityStatusReachableViaWWAN = 1, 蜂窝数据网络
20 | AFNetworkReachabilityStatusReachableViaWiFi = 2, WiFi
21 | };
22 | */
23 |
24 | [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
25 | switch (status) {
26 | case AFNetworkReachabilityStatusUnknown:
27 | NSLog(@"未知网络状态");
28 | break;
29 | case AFNetworkReachabilityStatusNotReachable:
30 | NSLog(@"无网络");
31 | break;
32 |
33 | case AFNetworkReachabilityStatusReachableViaWWAN:
34 | NSLog(@"蜂窝数据网");
35 | break;
36 |
37 | case AFNetworkReachabilityStatusReachableViaWiFi:
38 | NSLog(@"WiFi网络");
39 |
40 | break;
41 |
42 | default:
43 | break;
44 | }
45 | }];
46 | [manager startMonitoring];
47 |
48 | IDECodeSnippetIdentifier
49 | 6285E386-3B66-4C86-A176-D4E2C3749148
50 | IDECodeSnippetLanguage
51 | Xcode.SourceCodeLanguage.Objective-C
52 | IDECodeSnippetSummary
53 | 一键 监听网络状态 网络发生改变的时候触发回调
54 | IDECodeSnippetTitle
55 | AFNetworking3.0以上
56 | IDECodeSnippetUserSnippet
57 |
58 | IDECodeSnippetVersion
59 | 0
60 |
61 |
62 |
--------------------------------------------------------------------------------
/CodeSnippets/6773DBE1-3F3C-4F8A-B5FA-B3B65826DD70.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY Lable+Custom
7 | IDECodeSnippetCompletionScopes
8 |
9 | All
10 |
11 | IDECodeSnippetContents
12 | //uilabel+custom.m(UILabel的分类)
13 | //自适应宽度和高度
14 | + (CGFloat)getHeightByWidth:(CGFloat)width title:(NSString *)title font:(UIFont *)font
15 | {
16 |
17 | UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 0)];
18 | label.text = title;
19 | label.font = font;
20 | label.numberOfLines = 0;
21 | [label sizeToFit];
22 | CGFloat height = label.frame.size.height;
23 | return height;
24 | }
25 |
26 | + (CGFloat)getWidthWithTitle:(NSString *)title font:(UIFont *)font {
27 | UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 1000, 0)];
28 | label.text = title;
29 | label.font = font;
30 | [label sizeToFit];
31 | return label.frame.size.width;
32 | }
33 |
34 | IDECodeSnippetIdentifier
35 | 6773DBE1-3F3C-4F8A-B5FA-B3B65826DD70
36 | IDECodeSnippetLanguage
37 | Xcode.SourceCodeLanguage.Objective-C
38 | IDECodeSnippetSummary
39 | UIlabel的分类 让label自适应 高度 和 宽度
40 | IDECodeSnippetTitle
41 | UILabel+Custom
42 | IDECodeSnippetUserSnippet
43 |
44 | IDECodeSnippetVersion
45 | 0
46 |
47 |
48 |
--------------------------------------------------------------------------------
/CodeSnippets/75CBC3C4-E06B-4EA5-9CB9-2355EFF782A5.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY AlertController
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | UIAlertController *alert = [UIAlertController alertControllerWithTitle:<#(nullable NSString *)#> message:<#(nullable NSString *)#> preferredStyle:UIAlertControllerStyleAlert];
13 |
14 | UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
15 | NSLog(@"确定按键被点击");
16 | }];
17 | UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
18 | NSLog(@"取消按键被点击");
19 | }];
20 |
21 | [alert addAction:sureAction];
22 | [alert addAction:cancelAction];
23 | [self presentViewController:alert animated:YES completion:^{
24 | <#code#>
25 | }];
26 | IDECodeSnippetIdentifier
27 | 75CBC3C4-E06B-4EA5-9CB9-2355EFF782A5
28 | IDECodeSnippetLanguage
29 | Xcode.SourceCodeLanguage.Objective-C
30 | IDECodeSnippetSummary
31 | 一键创建警告框
32 | IDECodeSnippetTitle
33 | UIAlertController_alert
34 | IDECodeSnippetUserSnippet
35 |
36 | IDECodeSnippetVersion
37 | 0
38 |
39 |
40 |
--------------------------------------------------------------------------------
/CodeSnippets/7707FE2A-C6CF-4774-8A7D-EA6BEE058C11.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY Assign
7 | IDECodeSnippetCompletionScopes
8 |
9 | All
10 |
11 | IDECodeSnippetContents
12 | @property (nonatomic, assign) <#type#> <#name#>;
13 | IDECodeSnippetIdentifier
14 | 7707FE2A-C6CF-4774-8A7D-EA6BEE058C11
15 | IDECodeSnippetLanguage
16 | Xcode.SourceCodeLanguage.Objective-C
17 | IDECodeSnippetSummary
18 | Property declaration - assign
19 | IDECodeSnippetTitle
20 | Property declaration - assign
21 | IDECodeSnippetUserSnippet
22 |
23 | IDECodeSnippetVersion
24 | 2
25 |
26 |
27 |
--------------------------------------------------------------------------------
/CodeSnippets/7E58673D-D816-4B12-994E-89ACB0EC4EFF.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY AFN_GET
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
13 | //设置超时时间
14 | manager.requestSerializer.timeoutInterval = 15.0f;
15 | //manager.requestSerializer = [AFJSONRequestSerializer serializer];
16 | //manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
17 | [manager GET:@"" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
18 |
19 |
20 | } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
21 |
22 | NSLog(@"Sucess");
23 | } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
24 |
25 | NSLog(@"error %@",error);
26 | }];
27 | IDECodeSnippetIdentifier
28 | 7E58673D-D816-4B12-994E-89ACB0EC4EFF
29 | IDECodeSnippetLanguage
30 | Xcode.SourceCodeLanguage.Objective-C
31 | IDECodeSnippetSummary
32 | 一键生成 AFNetworking get 网络请求
33 | IDECodeSnippetTitle
34 | AFNetworking get 网络请求
35 | IDECodeSnippetUserSnippet
36 |
37 | IDECodeSnippetVersion
38 | 0
39 |
40 |
41 |
--------------------------------------------------------------------------------
/CodeSnippets/84587A91-678A-4727-9EBA-6F9D327EF485.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY NotificationCenter
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeExpression
10 |
11 | IDECodeSnippetContents
12 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(<#methodName#>) name:<#name#> object:nil];
13 | [[NSNotificationCenter defaultCenter] removeObserver:self];
14 | // post notification
15 | NSDictionary * userInfo = [NSDictionary dictionaryWithObject:<#NSObject#> forKey:<#key#>];
16 | [[NSNotificationCenter defaultCenter] postNotificationName:<#notification_name#> object:self userInfo:userInfo];
17 |
18 | - (void)<#functionname#>:(NSNotification*)notification
19 | IDECodeSnippetIdentifier
20 | 84587A91-678A-4727-9EBA-6F9D327EF485
21 | IDECodeSnippetLanguage
22 | Xcode.SourceCodeLanguage.Objective-C
23 | IDECodeSnippetSummary
24 | 一键发送 接收通知
25 | IDECodeSnippetTitle
26 | NSNotificationCenter
27 | IDECodeSnippetUserSnippet
28 |
29 | IDECodeSnippetVersion
30 | 2
31 |
32 |
33 |
--------------------------------------------------------------------------------
/CodeSnippets/8463A667-951C-46F7-840D-EACC85C27B3C.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY PageControl
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)];
13 |
14 | pageControl.numberOfPages = <#number#>;
15 |
16 | pageControl.currentPage = 0;
17 | //关闭左右控制按键
18 | pageControl.userInteractionEnabled = NO ;
19 | [<#superView#> addSubview:pageControl];
20 | IDECodeSnippetIdentifier
21 | 8463A667-951C-46F7-840D-EACC85C27B3C
22 | IDECodeSnippetLanguage
23 | Xcode.SourceCodeLanguage.Objective-C
24 | IDECodeSnippetSummary
25 | 一键创建 UIPageController
26 | IDECodeSnippetTitle
27 | UIPageControl
28 | IDECodeSnippetUserSnippet
29 |
30 | IDECodeSnippetVersion
31 | 2
32 |
33 |
34 |
--------------------------------------------------------------------------------
/CodeSnippets/853A4378-0888-45EF-85DB-10A9427E860E.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY ScrollView
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)];
13 |
14 | scrollView.pagingEnabled = YES; //是否整页滑动
15 | scrollView.contentSize = <#CGSize#>;
16 | //scrollView.contentOffset = <#CGPoint#> ;
17 | //隐藏滑动条 水平方向的
18 | scrollView.showsHorizontalScrollIndicator = NO;
19 | scrollView.showsVerticalScrollIndicator = NO;
20 | //关闭点击状态栏滑动到顶部
21 | scrollView.scrollsToTop = NO;
22 | // scrollView.bounces = YES ; //弹性属性
23 | //水平方向是否有弹性 (如果bounces设为NO,那么alwaysBounceHorizontal设置无效)
24 | // scrollView.alwaysBounceHorizontal = NO ;//水平
25 | // scrollView.alwaysBounceVertical = NO ;//垂直
26 | [<#superView#> addSubview:scrollView];
27 | IDECodeSnippetIdentifier
28 | 853A4378-0888-45EF-85DB-10A9427E860E
29 | IDECodeSnippetLanguage
30 | Xcode.SourceCodeLanguage.Objective-C
31 | IDECodeSnippetSummary
32 | 一键创建 UIScrollView
33 | IDECodeSnippetTitle
34 | UIScrollView
35 | IDECodeSnippetUserSnippet
36 |
37 | IDECodeSnippetVersion
38 | 2
39 |
40 |
41 |
--------------------------------------------------------------------------------
/CodeSnippets/872BFC2F-2F1F-48BE-AD9F-06B89D76C861.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY Dispatch_async
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | dispatch_async(dispatch_get_global_queue(0, 0), ^{
13 |
14 |
15 | dispatch_async(dispatch_get_main_queue(), ^{
16 |
17 |
18 | });
19 | });
20 | IDECodeSnippetIdentifier
21 | 872BFC2F-2F1F-48BE-AD9F-06B89D76C861
22 | IDECodeSnippetLanguage
23 | Xcode.SourceCodeLanguage.Objective-C
24 | IDECodeSnippetSummary
25 | 一键生成 子线程 到 主线程
26 | IDECodeSnippetTitle
27 | (GCD)Dispatch_async
28 | IDECodeSnippetUserSnippet
29 |
30 | IDECodeSnippetVersion
31 | 2
32 |
33 |
34 |
--------------------------------------------------------------------------------
/CodeSnippets/8D68DFE7-69E7-46E6-B4F0-F3C5EEC1BC12.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY interface
7 | IDECodeSnippetCompletionScopes
8 |
9 | TopLevel
10 |
11 | IDECodeSnippetContents
12 | @interface <#name#>()
13 |
14 | @end
15 |
16 | IDECodeSnippetIdentifier
17 | 8D68DFE7-69E7-46E6-B4F0-F3C5EEC1BC12
18 | IDECodeSnippetLanguage
19 | Xcode.SourceCodeLanguage.Objective-C
20 | IDECodeSnippetSummary
21 | add interface() extension
22 | IDECodeSnippetTitle
23 | add interface() extension
24 | IDECodeSnippetUserSnippet
25 |
26 | IDECodeSnippetVersion
27 | 2
28 |
29 |
30 |
--------------------------------------------------------------------------------
/CodeSnippets/8DC1C3D8-F7DD-4D73-8C58-9A8D8538DD6D.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY ActivityIndicatorView
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | UIActivityIndicatorView * activity = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)] ;
13 | //设定样式
14 | // UIActivityIndicatorViewStyleWhiteLarge,
15 | // UIActivityIndicatorViewStyleWhite,
16 | // UIActivityIndicatorViewStyleGray
17 | activity.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray ;
18 | activity.hidesWhenStopped = YES ;
19 | //开启动画
20 | [activity startAnimating] ;
21 | //关闭动画
22 | // [activity stopAnimating] ;
23 | [<#someView#> addSubview:activity];
24 | IDECodeSnippetIdentifier
25 | 8DC1C3D8-F7DD-4D73-8C58-9A8D8538DD6D
26 | IDECodeSnippetLanguage
27 | Xcode.SourceCodeLanguage.Objective-C
28 | IDECodeSnippetSummary
29 | 一键创建 菊花 附带 让菊花 转起来 暂定 action
30 | IDECodeSnippetTitle
31 | UIActivityIndicatorView
32 | IDECodeSnippetUserSnippet
33 |
34 | IDECodeSnippetVersion
35 | 0
36 |
37 |
38 |
--------------------------------------------------------------------------------
/CodeSnippets/93934053-BDF5-48C3-8B7F-08EB04D69442.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY init
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | self = [super init];
13 | if (self) {
14 | }
15 | return self;
16 | IDECodeSnippetIdentifier
17 | 93934053-BDF5-48C3-8B7F-08EB04D69442
18 | IDECodeSnippetLanguage
19 | Xcode.SourceCodeLanguage.Objective-C
20 | IDECodeSnippetSummary
21 | init code
22 | IDECodeSnippetTitle
23 | init code
24 | IDECodeSnippetUserSnippet
25 |
26 | IDECodeSnippetVersion
27 | 2
28 |
29 |
30 |
--------------------------------------------------------------------------------
/CodeSnippets/A22A7D0A-8EC9-4A4C-AD7C-F2A46D31FCCD.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY Slider
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | UISlider *slider = [[UISlider alloc]initWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)];
13 | //最小值
14 | slider.minimumValue = 0;
15 | //最大值
16 | slider.maximumValue = 1;
17 | //设定中间球的图片
18 | // [slider setThumbImage:[UIImage imageNamed:@"qiu"] forState:UIControlStateNormal];
19 | //右边颜色
20 | slider.maximumTrackTintColor = [UIColor grayColor];
21 | //左边颜色
22 | slider.minimumTrackTintColor = [UIColor yellowColor];
23 | slider.continuous = YES;
24 | slider.enabled = YES;
25 | //滑动事件 UIControlEventValueChanged
26 | [slider addTarget:self action:@selector(sliderchange:) forControlEvents:UIControlEventValueChanged] ;
27 | //滑动结束
28 | [slider addTarget:self action:@selector(sliderEnd) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside];
29 | [<#superView#> addSubview:slider];
30 |
31 |
32 | //每当值改变的时候调用
33 | -(void)sliderchange:(UISlider *) slider {
34 | float value = slider.value;
35 | NSLog(@"%lf",value);
36 | }
37 |
38 | //拖动结束的时候调用
39 | -(void)sliderEnd {
40 | NSLog(@"拖动结束");
41 | }
42 |
43 | IDECodeSnippetIdentifier
44 | A22A7D0A-8EC9-4A4C-AD7C-F2A46D31FCCD
45 | IDECodeSnippetLanguage
46 | Xcode.SourceCodeLanguage.Objective-C
47 | IDECodeSnippetSummary
48 | 一键创建 UISlider 附带值改变method 和 拖动结束 method
49 | IDECodeSnippetTitle
50 | UISlider
51 | IDECodeSnippetUserSnippet
52 |
53 | IDECodeSnippetVersion
54 | 0
55 |
56 |
57 |
--------------------------------------------------------------------------------
/CodeSnippets/A807145A-F6BD-412C-AA06-DC931E43F730.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY hide_keyboard
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassImplementation
10 |
11 | IDECodeSnippetContents
12 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
13 | [super touchesBegan:touches withEvent:event];
14 | [self.view endEditing:YES];
15 | }
16 |
17 | IDECodeSnippetIdentifier
18 | A807145A-F6BD-412C-AA06-DC931E43F730
19 | IDECodeSnippetLanguage
20 | Xcode.SourceCodeLanguage.Objective-C
21 | IDECodeSnippetSummary
22 | hide keyboard when touch background
23 | IDECodeSnippetTitle
24 | hide keyboard
25 | IDECodeSnippetUserSnippet
26 |
27 | IDECodeSnippetVersion
28 | 2
29 |
30 |
31 |
--------------------------------------------------------------------------------
/CodeSnippets/A83AE4CD-E79A-464F-B849-29BEB3CF4B01.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY Strong
7 | IDECodeSnippetCompletionScopes
8 |
9 | All
10 |
11 | IDECodeSnippetContents
12 | @property (nonatomic, strong) <#type#> *<#name#>;
13 | IDECodeSnippetIdentifier
14 | A83AE4CD-E79A-464F-B849-29BEB3CF4B01
15 | IDECodeSnippetLanguage
16 | Xcode.SourceCodeLanguage.Objective-C
17 | IDECodeSnippetSummary
18 | strong type property
19 | IDECodeSnippetTitle
20 | strong type property
21 | IDECodeSnippetUserSnippet
22 |
23 | IDECodeSnippetVersion
24 | 2
25 |
26 |
27 |
--------------------------------------------------------------------------------
/CodeSnippets/B9E1ED5F-F3D6-4479-A2DF-0C8B21740CD6.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY TableVIew Delegate/datasource
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassImplementation
10 |
11 | IDECodeSnippetContents
12 | #pragma mark - UITableView Datasource
13 |
14 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
15 | return 1;
16 | }
17 |
18 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
19 | return 10;
20 | }
21 |
22 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
23 | static NSString *cellIdentifier = @"Cell";
24 |
25 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
26 |
27 | if(cell == nil) {
28 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
29 | }
30 |
31 | cell.textLabel.text = [NSString stringWithFormat:@"Cell %d", indexPath.row];
32 |
33 | return cell;
34 | }
35 |
36 | #pragma mark - UITableView Delegate methods
37 |
38 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
39 |
40 | }
41 | IDECodeSnippetIdentifier
42 | B9E1ED5F-F3D6-4479-A2DF-0C8B21740CD6
43 | IDECodeSnippetLanguage
44 | Xcode.SourceCodeLanguage.Objective-C
45 | IDECodeSnippetSummary
46 | 一键 生成tableView 代理 method 和 DataSource method
47 | IDECodeSnippetTitle
48 | UITableView - Delegate - Datasource
49 | IDECodeSnippetUserSnippet
50 |
51 | IDECodeSnippetVersion
52 | 2
53 |
54 |
55 |
--------------------------------------------------------------------------------
/CodeSnippets/BC5A4D5B-EA3A-4B57-AC87-436F2A48D938.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY POST_yuansheng
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | NSString *urlStr = @"接口地址";
13 | NSURL *url = [NSURL URLWithString:urlStr];
14 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
15 | request.HTTPMethod = @"POST";
16 | //post参数
17 | NSString *value = @"value";
18 | NSString *value2 = @"value2";
19 | NSString *httpbodyString = [NSString stringWithFormat:@"key=%@&key2=%@",value,value2];
20 | request.HTTPBody = [httpbodyString dataUsingEncoding:NSUTF8StringEncoding];
21 | //请求头 HTTPHeader
22 | NSMutableURLRequest *mutableRequest = [request mutableCopy];
23 | [mutableRequest addValue:@"" forHTTPHeaderField:@"AGENT"];
24 | [mutableRequest addValue:@"" forHTTPHeaderField:@"AUTH"];
25 | //[mutableRequest addValue:@"multipart/form-data; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
26 | [mutableRequest addValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
27 | request = [mutableRequest copy];
28 |
29 | NSURLSession *session = [NSURLSession sharedSession];
30 | NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
31 | dispatch_async(dispatch_get_main_queue(), ^{
32 |
33 | if (error) {
34 | SSLog(@"=========== error ==========");
35 | } else {
36 | NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
37 | NSLog(@"%@",httpbodyString);
38 | NSLog(@"%@",dic);
39 | //解析dic 给Model赋值 或者 本地存储数据
40 |
41 | }
42 | });
43 |
44 | }];
45 | [dataTask resume];
46 | IDECodeSnippetIdentifier
47 | BC5A4D5B-EA3A-4B57-AC87-436F2A48D938
48 | IDECodeSnippetLanguage
49 | Xcode.SourceCodeLanguage.Objective-C
50 | IDECodeSnippetSummary
51 | 一键生成 POST 网络请求 IOS原生
52 | IDECodeSnippetTitle
53 | POST网络请求IOS原生
54 | IDECodeSnippetUserSnippet
55 |
56 | IDECodeSnippetVersion
57 | 0
58 |
59 |
60 |
--------------------------------------------------------------------------------
/CodeSnippets/BE20F1E7-4C7D-481D-9D8D-8CA1DB1F803E.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY Button
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
13 | [btn setBackgroundImage:<#(nullable UIImage *)#> forState:<#UIControlState#>];
14 | [btn setTitle:<#(nullable NSString *)#> forState:<#UIControlState#>];
15 | btn setTitleColor:<#(nullable UIColor *)#> forState:<#UIControlState#>;
16 | btn.frame = CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>);
17 | [<#superview#> addSubview:btn];
18 | IDECodeSnippetIdentifier
19 | BE20F1E7-4C7D-481D-9D8D-8CA1DB1F803E
20 | IDECodeSnippetLanguage
21 | Xcode.SourceCodeLanguage.Objective-C
22 | IDECodeSnippetSummary
23 | 一键创建 UIButton
24 | IDECodeSnippetTitle
25 | UIButton
26 | IDECodeSnippetUserSnippet
27 |
28 | IDECodeSnippetVersion
29 | 2
30 |
31 |
32 |
--------------------------------------------------------------------------------
/CodeSnippets/CF7257F4-1089-42C5-82E7-6A956C9F702B.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY DocPath
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | NSString *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
13 | NSString *filePath = [docPath stringByAppendingPathComponent:<#NSString#>];
14 | NSLog(@"filePaht %@", filePath);
15 | IDECodeSnippetIdentifier
16 | CF7257F4-1089-42C5-82E7-6A956C9F702B
17 | IDECodeSnippetLanguage
18 | Xcode.SourceCodeLanguage.Objective-C
19 | IDECodeSnippetSummary
20 | 一键 生成文件路径pathString
21 | IDECodeSnippetTitle
22 | DocumentPath filePath
23 | IDECodeSnippetUserSnippet
24 |
25 | IDECodeSnippetVersion
26 | 2
27 |
28 |
29 |
--------------------------------------------------------------------------------
/CodeSnippets/D1E528DB-F1FA-4A8A-8ABF-11391DEFE535.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY SegmentedControlduogeyipaianjian
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | UISegmentedControl * segment = [[UISegmentedControl alloc]initWithItems:<#@[@"第一个",@"第二个"....]#>] ;
13 | [segment addTarget:self action:@selector(valueChange:) forControlEvents:UIControlEventValueChanged];
14 | segment.frame = CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>);
15 | //改变选中状态
16 | segment.momentary = YES ;
17 | [<#someView#> addSubview:segment];
18 |
19 |
20 |
21 | //点击事件
22 | - (void)valueChange:(UISegmentedControl *)segment
23 | {
24 | if (segment.selectedSegmentIndex == 0 && segment.numberOfSegments >3)
25 | {
26 | NSLog(@"删除") ;
27 | //删除最后一个
28 | [segment removeSegmentAtIndex:segment.numberOfSegments-1 animated:YES] ;
29 | }
30 | else if (segment.selectedSegmentIndex == 1)
31 | {
32 | NSLog(@"图片") ;
33 | }
34 | else
35 | {
36 | //添加到第4个位置
37 | [segment insertSegmentWithTitle:@"标题" atIndex:3 animated:YES] ;
38 | NSLog(@"添加") ;
39 | }
40 | }
41 |
42 | IDECodeSnippetIdentifier
43 | D1E528DB-F1FA-4A8A-8ABF-11391DEFE535
44 | IDECodeSnippetLanguage
45 | Xcode.SourceCodeLanguage.Objective-C
46 | IDECodeSnippetSummary
47 | 一键创建多格按键 附带示例点击action
48 | IDECodeSnippetTitle
49 | UISegmentedControl
50 | IDECodeSnippetUserSnippet
51 |
52 | IDECodeSnippetVersion
53 | 0
54 |
55 |
56 |
--------------------------------------------------------------------------------
/CodeSnippets/E10BEAE2-7433-4892-9314-95759F276395.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY weak
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassInterfaceMethods
10 |
11 | IDECodeSnippetContents
12 | @property (nonatomic, weak) <#type#> *<#name#>;
13 | IDECodeSnippetIdentifier
14 | E10BEAE2-7433-4892-9314-95759F276395
15 | IDECodeSnippetLanguage
16 | Xcode.SourceCodeLanguage.Objective-C
17 | IDECodeSnippetTitle
18 | Property declaration - weak
19 | IDECodeSnippetUserSnippet
20 |
21 | IDECodeSnippetVersion
22 | 2
23 |
24 |
25 |
--------------------------------------------------------------------------------
/CodeSnippets/E1DCA19E-0BD3-4CF5-BFEA-16327ACBC64C.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY PickerView
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | //遵循两个代理<UIPickerViewDelegate,UIPickerViewDataSource>
13 | //@property (nonatomic, strong) UIPickerView *pickerView;
14 | //@property (nonatomic, strong) NSArray *array1;
15 | //@property (nonatomic, strong) NSArray *array2;
16 | self.array1 = @[@"星期一",@"星期二",@"星期三",@"星期四",@"星期五",@"星六一",@"星期七",@"星期八,这一天退休在家玩游戏"];
17 | self.array2 = @[@"星期一",@"星期二",@"星期三",@"星期四",@"星期五",@"星六一",@"星期七",@"星期八,这一天退休在家玩游戏"];
18 | self.pickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, 100, SCREEN_WIDTH, 120)];
19 | self.pickerView.backgroundColor = [UIColor grayColor];
20 | self.pickerView.delegate = self;
21 | self.pickerView.dataSource = self;
22 | self.pickerView.showsSelectionIndicator = YES;
23 | [self.view addSubview:_pickerView];
24 |
25 | //测试获取两个轮子的值
26 | UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
27 | btn.frame = CGRectMake(0, 300, SCREEN_WIDTH, 30);
28 | [btn setTitle:@"获取两个轮子上面的值" forState:UIControlStateNormal];
29 | [btn setBackgroundColor:[UIColor magentaColor]];
30 | [btn addTarget:self action:@selector(huoqulianggelunzishangmiandezhi) forControlEvents:UIControlEventTouchUpInside];
31 | [self.view addSubview:btn];
32 |
33 | #pragma mark - PickerView代理
34 | //滚轮个数
35 | -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
36 | {
37 | return 2;
38 | }
39 | //每个滚轮内的数据个数
40 | - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
41 | {
42 | if (component == 0) {
43 | //滚轮1
44 | return [self.array1 count];
45 | }
46 | //滚轮2
47 | return [self.array2 count];
48 | }
49 | //滚轮停止时调用
50 | -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
51 | if (component ==0) {
52 | //滚轮1
53 | NSString *str1 = [self.array1 objectAtIndex:row];
54 | NSLog(@"%@",str1);
55 | } else {
56 | //滚轮2
57 | NSString *str2 = [self.array2 objectAtIndex:row];
58 | NSLog(@"%@",str2);
59 | }
60 | }
61 | //设置滚轮宽度
62 | - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
63 | return 120;
64 | }
65 | //返回当前行的内容
66 | - (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
67 | if (component == 0) {
68 | return [self.array1 objectAtIndex:row];
69 | }
70 | return [self.array2 objectAtIndex:row];
71 | }
72 | //拿到当前滚轮选择数据
73 | - (void)huoqulianggelunzishangmiandezhi {
74 |
75 | //滚轮1
76 | NSInteger singgerow = [self.pickerView selectedRowInComponent:0];
77 | //滚轮2
78 | NSInteger singrow = [self.pickerView selectedRowInComponent:1];
79 | NSString *str = [NSString stringWithFormat:@"%@:%@",self.array1[singgerow],self.array2[singrow]];
80 | NSLog(@"%@",str);
81 | [_pickerView removeFromSuperview];
82 | }
83 | IDECodeSnippetIdentifier
84 | E1DCA19E-0BD3-4CF5-BFEA-16327ACBC64C
85 | IDECodeSnippetLanguage
86 | Xcode.SourceCodeLanguage.Objective-C
87 | IDECodeSnippetSummary
88 | 一键 自定义 UIPickerView Delegate/dataSource method
89 | IDECodeSnippetTitle
90 | UIPickerView
91 | IDECodeSnippetUserSnippet
92 |
93 | IDECodeSnippetVersion
94 | 0
95 |
96 |
97 |
--------------------------------------------------------------------------------
/CodeSnippets/E4A6DA59-C865-44F9-9BB3-5A946BE0B157.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY Label
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)];
13 | label.backgroundColor = [UIColor <#color#>];
14 | label.font = [UIFont systemFontOfSize:<#(CGFloat)#>];
15 | label.text = <#text#>;
16 | label.textAlignment = <#NSTextAlignment#>;
17 | [<#superview#> addSubview:label];
18 | IDECodeSnippetIdentifier
19 | E4A6DA59-C865-44F9-9BB3-5A946BE0B157
20 | IDECodeSnippetLanguage
21 | Xcode.SourceCodeLanguage.Objective-C
22 | IDECodeSnippetSummary
23 | 一键创建 UILabel
24 | IDECodeSnippetTitle
25 | UILabel
26 | IDECodeSnippetUserSnippet
27 |
28 | IDECodeSnippetVersion
29 | 2
30 |
31 |
32 |
--------------------------------------------------------------------------------
/CodeSnippets/E69F93F9-C828-443E-A2D6-C0AB47FE54AA.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY AFN_POST
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
13 | //设置超时时间
14 | manager.requestSerializer.timeoutInterval = 15.0f;
15 | //manager.requestSerializer = [AFJSONRequestSerializer serializer];
16 | //manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
17 |
18 | NSDictionary *parameters = @{@"1":@"2",@"3":@"4"};
19 |
20 | [manager POST:@"urlstring" parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
21 |
22 | NSLog(@"%lf",1.0 * uploadProgress.completedUnitCount / uploadProgress.totalUnitCount);
23 | } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
24 |
25 | NSLog(@"Sucess");
26 | } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
27 |
28 | NSLog(@"error %@",error);
29 | }];
30 | IDECodeSnippetIdentifier
31 | E69F93F9-C828-443E-A2D6-C0AB47FE54AA
32 | IDECodeSnippetLanguage
33 | Xcode.SourceCodeLanguage.Objective-C
34 | IDECodeSnippetSummary
35 | 一键生成 AFNetworking Post网络请求 带进度
36 | IDECodeSnippetTitle
37 | AFNetworking POST网络请求
38 | IDECodeSnippetUserSnippet
39 |
40 | IDECodeSnippetVersion
41 | 0
42 |
43 |
44 |
--------------------------------------------------------------------------------
/CodeSnippets/F2945E28-8E0F-4E27-8840-F40C4E7E7E5D.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY RequestDelegate
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassImplementation
10 |
11 | IDECodeSnippetContents
12 | #pragma mark - Network Request Delegate
13 |
14 | - (void)requestFinished:(BaseRequest *)request {
15 |
16 | }
17 |
18 | - (void)requestFailed:(BaseRequest *)request {
19 |
20 | }
21 |
22 | - (void)clearRequest {
23 |
24 | }
25 |
26 | IDECodeSnippetIdentifier
27 | F2945E28-8E0F-4E27-8840-F40C4E7E7E5D
28 | IDECodeSnippetLanguage
29 | Xcode.SourceCodeLanguage.Objective-C
30 | IDECodeSnippetSummary
31 | 一键创建networkRequestDelegate
32 | IDECodeSnippetTitle
33 | networkRequestDelegate
34 | IDECodeSnippetUserSnippet
35 |
36 | IDECodeSnippetVersion
37 | 2
38 |
39 |
40 |
--------------------------------------------------------------------------------
/CodeSnippets/F95F0606-30C9-41A8-9732-6D055E009DF0.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY CornerRadius
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | //圆角
13 | <#UI#>.layer.masksToBounds = YES;
14 | <#UI#>.layer.cornerRadius = <#CGFloat#>;
15 |
16 | //边框
17 | <#UI#>.layer.borderWidth = <#CGFloat#>;
18 | <#UI#>.layer.borderColor = <#UIColor#>.CGColor;
19 | IDECodeSnippetIdentifier
20 | F95F0606-30C9-41A8-9732-6D055E009DF0
21 | IDECodeSnippetLanguage
22 | Xcode.SourceCodeLanguage.Objective-C
23 | IDECodeSnippetSummary
24 | 一键设置UI的圆角 边框
25 | IDECodeSnippetTitle
26 | MakeCornerRadius
27 | IDECodeSnippetUserSnippet
28 |
29 | IDECodeSnippetVersion
30 | 2
31 |
32 |
33 |
--------------------------------------------------------------------------------
/CodeSnippets/FE25181C-41FC-436A-B948-6ADE2961E4FE.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | YY Window
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
13 | self.window.backgroundColor = [UIColor whiteColor];
14 | self.window.rootViewController = <#rootViewController#>;
15 | [self.window makeKeyAndVisible];
16 | IDECodeSnippetIdentifier
17 | FE25181C-41FC-436A-B948-6ADE2961E4FE
18 | IDECodeSnippetLanguage
19 | Xcode.SourceCodeLanguage.Objective-C
20 | IDECodeSnippetSummary
21 | 一键创建UIWindow
22 | IDECodeSnippetTitle
23 | UIWindow
24 | IDECodeSnippetUserSnippet
25 |
26 | IDECodeSnippetVersion
27 | 2
28 |
29 |
30 |
--------------------------------------------------------------------------------
/IAP/RNCryptor/include/RNCryptor+Private.h:
--------------------------------------------------------------------------------
1 | //
2 | // RNCryptor(Private)
3 | //
4 | // Copyright (c) 2012 Rob Napier
5 | //
6 | // This code is licensed under the MIT License:
7 | //
8 | // Permission is hereby granted, free of charge, to any person obtaining a
9 | // copy of this software and associated documentation files (the "Software"),
10 | // to deal in the Software without restriction, including without limitation
11 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 | // and/or sell copies of the Software, and to permit persons to whom the
13 | // Software is furnished to do so, subject to the following conditions:
14 | //
15 | // The above copyright notice and this permission notice shall be included in
16 | // all copies or substantial portions of the Software.
17 | //
18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 | // DEALINGS IN THE SOFTWARE.
25 | //
26 |
27 | #import
28 | #import "RNCryptor.h"
29 |
30 | @class RNCryptorEngine;
31 |
32 | @interface RNCryptor ()
33 | @property (nonatomic, readwrite, strong) RNCryptorEngine *engine;
34 | #if OS_OBJECT_USE_OBJC
35 | @property (nonatomic, readwrite, strong) dispatch_queue_t queue;
36 | #else
37 | @property (nonatomic, readwrite, assign) dispatch_queue_t queue;
38 | #endif
39 | @property (nonatomic, readonly) NSMutableData *outData;
40 | @property (nonatomic, readwrite, copy) RNCryptorHandler handler;
41 | @property (nonatomic, readwrite, assign) NSUInteger HMACLength;
42 | @property (nonatomic, readwrite, strong) NSError *error;
43 | @property (nonatomic, readwrite, assign, getter=isFinished) BOOL finished;
44 | @property (nonatomic, readwrite, assign) RNCryptorOptions options;
45 |
46 | - (id)initWithHandler:(RNCryptorHandler)handler;
47 | + (NSData *)synchronousResultForCryptor:(RNCryptor *)cryptor data:(NSData *)inData error:(NSError **)anError;
48 | - (void)cleanupAndNotifyWithError:(NSError *)error;
49 | - (BOOL)hasHMAC;
50 | @end
51 |
52 | @interface NSMutableData (RNCryptor)
53 | - (NSData *)_RNConsumeToIndex:(NSUInteger)index;
54 | @end
55 |
--------------------------------------------------------------------------------
/IAP/RNCryptor/include/RNCryptor.h:
--------------------------------------------------------------------------------
1 | //
2 | // RNCryptor.h
3 | //
4 | // Copyright (c) 2012 Rob Napier
5 | //
6 | // This code is licensed under the MIT License:
7 | //
8 | // Permission is hereby granted, free of charge, to any person obtaining a
9 | // copy of this software and associated documentation files (the "Software"),
10 | // to deal in the Software without restriction, including without limitation
11 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 | // and/or sell copies of the Software, and to permit persons to whom the
13 | // Software is furnished to do so, subject to the following conditions:
14 | //
15 | // The above copyright notice and this permission notice shall be included in
16 | // all copies or substantial portions of the Software.
17 | //
18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 | // DEALINGS IN THE SOFTWARE.
25 | //
26 |
27 | #import
28 | #import
29 |
30 | // NOTE: No CommonCrypto types may be used in this file. Swift can't handle them.
31 |
32 | extern NSString *const kRNCryptorErrorDomain;
33 | extern const uint8_t kRNCryptorFileVersion;
34 |
35 | typedef struct _RNCryptorKeyDerivationSettings
36 | {
37 | size_t keySize;
38 | size_t saltSize;
39 | /* CCPBKDFAlgorithm */ uint32_t PBKDFAlgorithm;
40 | /* CCPseudoRandomAlgorithm */ uint32_t PRF;
41 | uint rounds;
42 | BOOL hasV2Password; // See Issue #77. V2 incorrectly handled multi-byte characters.
43 | } RNCryptorKeyDerivationSettings;
44 |
45 | typedef struct _RNCryptorSettings
46 | {
47 | /* CCAlgorithm */ uint32_t algorithm;
48 | size_t blockSize;
49 | size_t IVSize;
50 | /* CCOptions */ uint32_t options;
51 | /* CCHmacAlgorithm */ uint32_t HMACAlgorithm;
52 | size_t HMACLength;
53 | RNCryptorKeyDerivationSettings keySettings;
54 | RNCryptorKeyDerivationSettings HMACKeySettings;
55 | } RNCryptorSettings;
56 |
57 | extern const RNCryptorSettings kRNCryptorAES256Settings;
58 |
59 | enum _RNCryptorOptions
60 | {
61 | kRNCryptorOptionHasPassword = 1 << 0,
62 | };
63 | typedef uint8_t RNCryptorOptions;
64 |
65 | enum
66 | {
67 | kRNCryptorHMACMismatch = 1,
68 | kRNCryptorUnknownHeader = 2,
69 | };
70 |
71 | @class RNCryptor;
72 |
73 | typedef void (^RNCryptorHandler)(RNCryptor *cryptor, NSData *data);
74 |
75 | ///** Encryptor/Decryptor for iOS
76 | //
77 | // Provides an easy-to-use, Objective-C interface to the AES functionality of CommonCrypto. Simplifies correct handling of
78 | // password stretching (PBKDF2), salting, and IV. For more information on these terms, see "Properly encrypting with AES
79 | // with CommonCrypto," and iOS 5 Programming Pushing the Limits, Chapter 11. Also includes automatic HMAC handling to integrity-check messages.
80 | //
81 | // RNCryptor is abstract. Use RNEncryptor to encrypt or RNDecryptor to decrypt
82 | // */
83 | //
84 |
85 | @interface RNCryptor : NSObject
86 | @property (nonatomic, readonly, strong) NSError *error;
87 | @property (nonatomic, readonly, getter=isFinished) BOOL finished;
88 | @property (nonatomic, readonly, copy) RNCryptorHandler handler;
89 | @property (nonatomic, readwrite) dispatch_queue_t responseQueue;
90 |
91 | - (void)addData:(NSData *)data;
92 | - (void)finish;
93 |
94 | /** Generate key given a password and salt using a PBKDF
95 | *
96 | * @param password Password to use for PBKDF
97 | * @param salt Salt for password
98 | * @param keySettings Settings for the derivation (RNCryptorKeyDerivationSettings)
99 | * @returns Key
100 | * @throws if settings are illegal
101 | */
102 | + (NSData *)keyForPassword:(NSString *)password salt:(NSData *)salt settings:(RNCryptorKeyDerivationSettings)keySettings;
103 |
104 | /** Generate random data
105 | *
106 | * @param length Length of data to generate
107 | * @returns random data
108 | */
109 | + (NSData *)randomDataOfLength:(size_t)length;
110 |
111 | @end
112 |
--------------------------------------------------------------------------------
/IAP/RNCryptor/include/RNCryptorEngine.h:
--------------------------------------------------------------------------------
1 | //
2 | // RNCryptorEngine
3 | //
4 | // Copyright (c) 2012 Rob Napier
5 | //
6 | // This code is licensed under the MIT License:
7 | //
8 | // Permission is hereby granted, free of charge, to any person obtaining a
9 | // copy of this software and associated documentation files (the "Software"),
10 | // to deal in the Software without restriction, including without limitation
11 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 | // and/or sell copies of the Software, and to permit persons to whom the
13 | // Software is furnished to do so, subject to the following conditions:
14 | //
15 | // The above copyright notice and this permission notice shall be included in
16 | // all copies or substantial portions of the Software.
17 | //
18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 | // DEALINGS IN THE SOFTWARE.
25 | //
26 |
27 | #import
28 | #import
29 | #import "RNCryptor.h"
30 |
31 | @interface RNCryptorEngine : NSObject
32 | - (RNCryptorEngine *)initWithOperation:(CCOperation)operation settings:(RNCryptorSettings)settings key:(NSData *)key IV:(NSData *)IV error:(NSError **)error;
33 | - (NSData *)addData:(NSData *)data error:(NSError **)error;
34 | - (NSData *)finishWithError:(NSError **)error;
35 | @end
36 |
--------------------------------------------------------------------------------
/IAP/RNCryptor/include/RNDecryptor.h:
--------------------------------------------------------------------------------
1 | //
2 | // RNDecryptor
3 | //
4 | // Copyright (c) 2012 Rob Napier
5 | //
6 | // This code is licensed under the MIT License:
7 | //
8 | // Permission is hereby granted, free of charge, to any person obtaining a
9 | // copy of this software and associated documentation files (the "Software"),
10 | // to deal in the Software without restriction, including without limitation
11 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 | // and/or sell copies of the Software, and to permit persons to whom the
13 | // Software is furnished to do so, subject to the following conditions:
14 | //
15 | // The above copyright notice and this permission notice shall be included in
16 | // all copies or substantial portions of the Software.
17 | //
18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 | // DEALINGS IN THE SOFTWARE.
25 | //
26 |
27 | #import
28 | #import "RNCryptor.h"
29 |
30 |
31 | @interface RNDecryptor : RNCryptor
32 |
33 | - (RNDecryptor *)initWithEncryptionKey:(NSData *)encryptionKey
34 | HMACKey:(NSData *)HMACKey
35 | handler:(RNCryptorHandler)handler;
36 |
37 | - (RNDecryptor *)initWithPassword:(NSString *)password
38 | handler:(RNCryptorHandler)handler;
39 |
40 | + (NSData *)decryptData:(NSData *)theCipherText withSettings:(RNCryptorSettings)settings password:(NSString *)aPassword error:(NSError **)anError;
41 | + (NSData *)decryptData:(NSData *)theCipherText withSettings:(RNCryptorSettings)settings encryptionKey:(NSData *)encryptionKey HMACKey:(NSData *)HMACKey error:(NSError **)anError;
42 |
43 | + (NSData *)decryptData:(NSData *)data withPassword:(NSString *)password error:(NSError **)error;
44 | + (NSData *)decryptData:(NSData *)data withEncryptionKey:(NSData *)encryptionKey HMACKey:(NSData *)HMACKey error:(NSError **)error;
45 |
46 | @end
47 |
--------------------------------------------------------------------------------
/IAP/RNCryptor/include/RNEncryptor.h:
--------------------------------------------------------------------------------
1 | //
2 | // RNEncryptor
3 | //
4 | // Copyright (c) 2012 Rob Napier
5 | //
6 | // This code is licensed under the MIT License:
7 | //
8 | // Permission is hereby granted, free of charge, to any person obtaining a
9 | // copy of this software and associated documentation files (the "Software"),
10 | // to deal in the Software without restriction, including without limitation
11 | // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 | // and/or sell copies of the Software, and to permit persons to whom the
13 | // Software is furnished to do so, subject to the following conditions:
14 | //
15 | // The above copyright notice and this permission notice shall be included in
16 | // all copies or substantial portions of the Software.
17 | //
18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 | // DEALINGS IN THE SOFTWARE.
25 | //
26 |
27 | #import
28 | #import "RNCryptor.h"
29 |
30 | @interface RNEncryptor : RNCryptor
31 | - (RNEncryptor *)initWithSettings:(RNCryptorSettings)settings
32 | encryptionKey:(NSData *)encryptionKey
33 | HMACKey:(NSData *)HMACKey
34 | handler:(RNCryptorHandler)handler;
35 |
36 |
37 | - (RNEncryptor *)initWithSettings:(RNCryptorSettings)settings
38 | password:(NSString *)password
39 | handler:(RNCryptorHandler)handler;
40 |
41 | // This form with manual IV is generally only used for testing
42 | - (RNEncryptor *)initWithSettings:(RNCryptorSettings)theSettings
43 | encryptionKey:(NSData *)anEncryptionKey
44 | HMACKey:(NSData *)anHMACKey
45 | IV:(NSData *)anIV
46 | handler:(RNCryptorHandler)aHandler;
47 |
48 | // This form with manual IV and salts is generally only used for testing
49 | - (RNEncryptor *)initWithSettings:(RNCryptorSettings)settings
50 | password:(NSString *)password
51 | IV:(NSData *)anIV
52 | encryptionSalt:(NSData *)anEncryptionSalt
53 | HMACSalt:(NSData *)anHMACSalt
54 | handler:(RNCryptorHandler)handler;
55 |
56 |
57 | + (NSData *)encryptData:(NSData *)data withSettings:(RNCryptorSettings)settings password:(NSString *)password error:(NSError **)error;
58 | + (NSData *)encryptData:(NSData *)data withSettings:(RNCryptorSettings)settings encryptionKey:(NSData *)encryptionKey HMACKey:(NSData *)HMACKey error:(NSError **)error;
59 |
60 | // This form with manual IV is generally only used for testing
61 | + (NSData *)encryptData:(NSData *)thePlaintext
62 | withSettings:(RNCryptorSettings)theSettings
63 | encryptionKey:(NSData *)anEncryptionKey
64 | HMACKey:(NSData *)anHMACKey
65 | IV:(NSData *)anIV
66 | error:(NSError **)anError;
67 |
68 | // This form with manual IV and salts is generally only used for testing
69 | + (NSData *)encryptData:(NSData *)data
70 | withSettings:(RNCryptorSettings)settings
71 | password:(NSString *)password
72 | IV:(NSData *)anIV
73 | encryptionSalt:(NSData *)anEncryptionSalt
74 | HMACSalt:(NSData *)anHMACSalt
75 | error:(NSError **)error;
76 |
77 | @end
78 |
--------------------------------------------------------------------------------
/IAP/RNCryptor/libRNCryptor.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MulticolourSpider/YY_Tool/8b80eaa944090bed19420249eae74a46c97698f3/IAP/RNCryptor/libRNCryptor.a
--------------------------------------------------------------------------------
/IAP/Security/.svn/entries:
--------------------------------------------------------------------------------
1 | 12
2 |
--------------------------------------------------------------------------------
/IAP/Security/.svn/format:
--------------------------------------------------------------------------------
1 | 12
2 |
--------------------------------------------------------------------------------
/IAP/Security/.svn/pristine/14/144b7746ff05b8c87d60061591b55e5f70d039dd.svn-base:
--------------------------------------------------------------------------------
1 | //
2 | // NSString+MD5Encrypt.m
3 | // MOA
4 | //
5 | // Created by on 12-2-7.
6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import "NSString+MD5Encrypt.h"
10 |
11 | @implementation NSString (md5)
12 |
13 | -(NSString *) md5Encrypt {
14 | const char *original_str = [self UTF8String];
15 | unsigned char result[CC_MD5_DIGEST_LENGTH];
16 | CC_MD5(original_str, strlen(original_str), result);
17 | NSMutableString *hash = [NSMutableString string];
18 | for (int i = 0; i < 16; i++)
19 | [hash appendFormat:@"%02X", result[i]];
20 | return [hash lowercaseString];
21 | }
22 |
23 | @end
24 |
--------------------------------------------------------------------------------
/IAP/Security/.svn/pristine/19/19ef1c9db6c786a82e30b58be473170360ed3719.svn-base:
--------------------------------------------------------------------------------
1 | //
2 | // Base64Utility.h
3 | // GLPaint
4 | //
5 | // Created by gao_yufeng on 8/4/11.
6 | // Copyright 2011 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 |
12 | @interface Base64Utility : NSObject {
13 |
14 |
15 | }
16 |
17 | + (NSString*)encodeBase64WithNSString:(NSString *)input;
18 | + (NSString*)decodeBase64WithNSString:(NSString *)input;
19 | + (NSString*)encodeBase64WithNSData:(NSData *)data;
20 | + (NSString*)decodeBase64WithNSData:(NSData *)data;
21 |
22 | @end
23 |
--------------------------------------------------------------------------------
/IAP/Security/.svn/pristine/2c/2c099529c402e61ac13c440b6792e13361c84c20.svn-base:
--------------------------------------------------------------------------------
1 | //
2 | // NSString+MD5Encrypt.h
3 | // MOA
4 | //
5 | // Created by on 12-2-7.
6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface NSString (md5)
12 |
13 | -(NSString *) md5Encrypt;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/IAP/Security/.svn/pristine/3b/3b8cc33d1218668dc0cc108077dce356941a9858.svn-base:
--------------------------------------------------------------------------------
1 | //
2 | // Base64Utility.m
3 | // GLPaint
4 | //
5 | // Created by gao_yufeng on 8/4/11.
6 | // Copyright 2011 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import "Base64Utility.h"
10 | #import "GTMBase64.h"
11 |
12 | @implementation Base64Utility
13 |
14 | + (NSString*)encodeBase64WithNSString:(NSString * )input
15 | {
16 | NSData *data = [input dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
17 | data = [GTMBase64 encodeData:data];
18 | NSString *base64String = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
19 | return base64String;
20 | }
21 | + (NSString*)decodeBase64WithNSString:(NSString * )input
22 | {
23 | NSData *data = [input dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
24 | data = [GTMBase64 decodeData:data];
25 | NSString *base64String = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
26 | return base64String;
27 | }
28 |
29 | + (NSString*)encodeBase64WithNSData:(NSData *)data{
30 | data = [GTMBase64 encodeData:data];
31 | NSString *base64String = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
32 | return base64String;
33 | }
34 |
35 | + (NSString*)decodeBase64WithNSData:(NSData *)data{
36 | data = [GTMBase64 decodeData:data];
37 | NSString *base64String = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
38 | return base64String;
39 | }
40 | @end
41 |
--------------------------------------------------------------------------------
/IAP/Security/.svn/pristine/59/59ae2cd489f0ae59d554a6992cdb6e8d4fe106fb.svn-base:
--------------------------------------------------------------------------------
1 | //
2 | // NSData-AES.h
3 | //
4 | // Created by on 2012-2-6.
5 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
6 | //
7 |
8 | #import
9 |
10 | @class NSString;
11 |
12 | @interface NSData (Encryption)
13 |
14 | - (NSData *)AES256EncryptWithKey:(NSString *)key; //加密
15 | - (NSData *)AES256DecryptWithKey:(NSString *)key; //解密
16 | - (NSString *)newStringInBase64FromData; //追加64编码
17 | + (NSString*)base64encode:(NSString*)str; //同上64编码
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/IAP/Security/.svn/pristine/fb/fbd022ba7ee80f72f3b7ae8fd6c55b53d5bd9c75.svn-base:
--------------------------------------------------------------------------------
1 | //
2 | // NSData-AES.m
3 | //
4 | // Created by on 2012-2-6.
5 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
6 | //
7 |
8 | #import "NSData+AES.h"
9 | #import
10 |
11 |
12 | static char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
13 |
14 | @implementation NSData (Encryption)
15 |
16 | - (NSData *)AES256EncryptWithKey:(NSString *)key //加密
17 | {
18 | char keyPtr[kCCKeySizeAES256+1];
19 | bzero(keyPtr, sizeof(keyPtr));
20 | [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
21 | NSUInteger dataLength = [self length];
22 | size_t bufferSize = dataLength + kCCBlockSizeAES128;
23 | void *buffer = malloc(bufferSize);
24 | size_t numBytesEncrypted = 0;
25 | CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, kCCAlgorithmAES128,
26 | kCCOptionPKCS7Padding | kCCOptionECBMode,
27 | keyPtr, kCCBlockSizeAES128,
28 | NULL,
29 | [self bytes], dataLength,
30 | buffer, bufferSize,
31 | &numBytesEncrypted);
32 | if (cryptStatus == kCCSuccess) {
33 | return [NSData dataWithBytesNoCopy:buffer length:numBytesEncrypted];
34 | }
35 | free(buffer);
36 | return nil;
37 | }
38 |
39 |
40 | - (NSData *)AES256DecryptWithKey:(NSString *)key //解密
41 | {
42 | char keyPtr[kCCKeySizeAES256+1];
43 | bzero(keyPtr, sizeof(keyPtr));
44 | [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
45 | NSUInteger dataLength = [self length];
46 | size_t bufferSize = dataLength + kCCBlockSizeAES128;
47 | void *buffer = malloc(bufferSize);
48 | size_t numBytesDecrypted = 0;
49 | CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, kCCAlgorithmAES128,
50 | kCCOptionPKCS7Padding | kCCOptionECBMode,
51 | keyPtr, kCCBlockSizeAES128,
52 | NULL,
53 | [self bytes], dataLength,
54 | buffer, bufferSize,
55 | &numBytesDecrypted);
56 | if (cryptStatus == kCCSuccess) {
57 | return [NSData dataWithBytesNoCopy:buffer length:numBytesDecrypted];
58 | }
59 | free(buffer);
60 | return nil;
61 | }
62 |
63 |
64 | - (NSString *)newStringInBase64FromData //追加64编码
65 | {
66 | NSMutableString *dest = [[NSMutableString alloc] initWithString:@""];
67 | unsigned char * working = (unsigned char *)[self bytes];
68 | int srcLen = [self length];
69 | for (int i=0; i= srcLen) break;
74 | unsigned char curr = ((working[i+byt] << (8-ix)) & 0x3F);
75 | if (i+nib < srcLen) curr |= ((working[i+nib] >> ix) & 0x3F);
76 | [dest appendFormat:@"%c", base64[curr]];
77 | }
78 | }
79 | return dest;
80 | }
81 |
82 | + (NSString*)base64encode:(NSString*)str
83 | {
84 | if ([str length] == 0)
85 | return @"";
86 | const char *source = [str UTF8String];
87 | int strlength = strlen(source);
88 | char *characters = malloc(((strlength + 2) / 3) * 4);
89 | if (characters == NULL)
90 | return nil;
91 | NSUInteger length = 0;
92 | NSUInteger i = 0;
93 | while (i < strlength) {
94 | char buffer[3] = {0,0,0};
95 | short bufferLength = 0;
96 | while (bufferLength < 3 && i < strlength)
97 | buffer[bufferLength++] = source[i++];
98 | characters[length++] = base64[(buffer[0] & 0xFC) >> 2];
99 | characters[length++] = base64[((buffer[0] & 0x03) << 4) | ((buffer[1] & 0xF0) >> 4)];
100 | if (bufferLength > 1)
101 | characters[length++] = base64[((buffer[1] & 0x0F) << 2) | ((buffer[2] & 0xC0) >> 6)];
102 | else characters[length++] = '=';
103 | if (bufferLength > 2)
104 | characters[length++] = base64[buffer[2] & 0x3F];
105 | else characters[length++] = '=';
106 | }
107 | NSString *g = [[[NSString alloc] initWithBytesNoCopy:characters length:length encoding:NSASCIIStringEncoding freeWhenDone:YES] autorelease];
108 | return g;
109 | }
110 |
111 |
112 | @end
113 |
--------------------------------------------------------------------------------
/IAP/Security/.svn/wc.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MulticolourSpider/YY_Tool/8b80eaa944090bed19420249eae74a46c97698f3/IAP/Security/.svn/wc.db
--------------------------------------------------------------------------------
/IAP/Security/GTMBase64/GTMBase64.h:
--------------------------------------------------------------------------------
1 | //
2 | // GTMBase64.h
3 | //
4 | // Copyright 2006-2008 Google Inc.
5 | //
6 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
7 | // use this file except in compliance with the License. You may obtain a copy
8 | // of the License at
9 | //
10 |
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 | // License for the specific language governing permissions and limitations under
16 | // the License.
17 | //
18 |
19 | // 版权属于原作者
20 |
21 | // 发布代码于最专业的源码分享网站: Code4App.com
22 |
23 | #import
24 | #import "GTMDefines.h"
25 |
26 | // GTMBase64
27 | //
28 | /// Helper for handling Base64 and WebSafeBase64 encodings
29 | //
30 | /// The webSafe methods use different character set and also the results aren't
31 | /// always padded to a multiple of 4 characters. This is done so the resulting
32 | /// data can be used in urls and url query arguments without needing any
33 | /// encoding. You must use the webSafe* methods together, the data does not
34 | /// interop with the RFC methods.
35 | //
36 | @interface GTMBase64 : NSObject
37 |
38 | //
39 | // Standard Base64 (RFC) handling
40 | //
41 |
42 | // encodeData:
43 | //
44 | /// Base64 encodes contents of the NSData object.
45 | //
46 | /// Returns:
47 | /// A new autoreleased NSData with the encoded payload. nil for any error.
48 | //
49 | +(NSData *)encodeData:(NSData *)data;
50 |
51 | // decodeData:
52 | //
53 | /// Base64 decodes contents of the NSData object.
54 | //
55 | /// Returns:
56 | /// A new autoreleased NSData with the decoded payload. nil for any error.
57 | //
58 | +(NSData *)decodeData:(NSData *)data;
59 |
60 | // encodeBytes:length:
61 | //
62 | /// Base64 encodes the data pointed at by |bytes|.
63 | //
64 | /// Returns:
65 | /// A new autoreleased NSData with the encoded payload. nil for any error.
66 | //
67 | +(NSData *)encodeBytes:(const void *)bytes length:(NSUInteger)length;
68 |
69 | // decodeBytes:length:
70 | //
71 | /// Base64 decodes the data pointed at by |bytes|.
72 | //
73 | /// Returns:
74 | /// A new autoreleased NSData with the encoded payload. nil for any error.
75 | //
76 | +(NSData *)decodeBytes:(const void *)bytes length:(NSUInteger)length;
77 |
78 | // stringByEncodingData:
79 | //
80 | /// Base64 encodes contents of the NSData object.
81 | //
82 | /// Returns:
83 | /// A new autoreleased NSString with the encoded payload. nil for any error.
84 | //
85 | +(NSString *)stringByEncodingData:(NSData *)data;
86 |
87 | // stringByEncodingBytes:length:
88 | //
89 | /// Base64 encodes the data pointed at by |bytes|.
90 | //
91 | /// Returns:
92 | /// A new autoreleased NSString with the encoded payload. nil for any error.
93 | //
94 | +(NSString *)stringByEncodingBytes:(const void *)bytes length:(NSUInteger)length;
95 |
96 | // decodeString:
97 | //
98 | /// Base64 decodes contents of the NSString.
99 | //
100 | /// Returns:
101 | /// A new autoreleased NSData with the decoded payload. nil for any error.
102 | //
103 | +(NSData *)decodeString:(NSString *)string;
104 |
105 | //
106 | // Modified Base64 encoding so the results can go onto urls.
107 | //
108 | // The changes are in the characters generated and also allows the result to
109 | // not be padded to a multiple of 4.
110 | // Must use the matching call to encode/decode, won't interop with the
111 | // RFC versions.
112 | //
113 |
114 | // webSafeEncodeData:padded:
115 | //
116 | /// WebSafe Base64 encodes contents of the NSData object. If |padded| is YES
117 | /// then padding characters are added so the result length is a multiple of 4.
118 | //
119 | /// Returns:
120 | /// A new autoreleased NSData with the encoded payload. nil for any error.
121 | //
122 | +(NSData *)webSafeEncodeData:(NSData *)data
123 | padded:(BOOL)padded;
124 |
125 | // webSafeDecodeData:
126 | //
127 | /// WebSafe Base64 decodes contents of the NSData object.
128 | //
129 | /// Returns:
130 | /// A new autoreleased NSData with the decoded payload. nil for any error.
131 | //
132 | +(NSData *)webSafeDecodeData:(NSData *)data;
133 |
134 | // webSafeEncodeBytes:length:padded:
135 | //
136 | /// WebSafe Base64 encodes the data pointed at by |bytes|. If |padded| is YES
137 | /// then padding characters are added so the result length is a multiple of 4.
138 | //
139 | /// Returns:
140 | /// A new autoreleased NSData with the encoded payload. nil for any error.
141 | //
142 | +(NSData *)webSafeEncodeBytes:(const void *)bytes
143 | length:(NSUInteger)length
144 | padded:(BOOL)padded;
145 |
146 | // webSafeDecodeBytes:length:
147 | //
148 | /// WebSafe Base64 decodes the data pointed at by |bytes|.
149 | //
150 | /// Returns:
151 | /// A new autoreleased NSData with the encoded payload. nil for any error.
152 | //
153 | +(NSData *)webSafeDecodeBytes:(const void *)bytes length:(NSUInteger)length;
154 |
155 | // stringByWebSafeEncodingData:padded:
156 | //
157 | /// WebSafe Base64 encodes contents of the NSData object. If |padded| is YES
158 | /// then padding characters are added so the result length is a multiple of 4.
159 | //
160 | /// Returns:
161 | /// A new autoreleased NSString with the encoded payload. nil for any error.
162 | //
163 | +(NSString *)stringByWebSafeEncodingData:(NSData *)data
164 | padded:(BOOL)padded;
165 |
166 | // stringByWebSafeEncodingBytes:length:padded:
167 | //
168 | /// WebSafe Base64 encodes the data pointed at by |bytes|. If |padded| is YES
169 | /// then padding characters are added so the result length is a multiple of 4.
170 | //
171 | /// Returns:
172 | /// A new autoreleased NSString with the encoded payload. nil for any error.
173 | //
174 | +(NSString *)stringByWebSafeEncodingBytes:(const void *)bytes
175 | length:(NSUInteger)length
176 | padded:(BOOL)padded;
177 |
178 | // webSafeDecodeString:
179 | //
180 | /// WebSafe Base64 decodes contents of the NSString.
181 | //
182 | /// Returns:
183 | /// A new autoreleased NSData with the decoded payload. nil for any error.
184 | //
185 | +(NSData *)webSafeDecodeString:(NSString *)string;
186 |
187 | @end
188 |
--------------------------------------------------------------------------------
/IAP/Security/GTMBase64/GTMBase64.m:
--------------------------------------------------------------------------------
1 | //
2 | // GTMBase64.m
3 | //
4 | // Copyright 2006-2008 Google Inc.
5 | //
6 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
7 | // use this file except in compliance with the License. You may obtain a copy
8 | // of the License at
9 |
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 | // License for the specific language governing permissions and limitations under
15 | // the License.
16 | //
17 |
18 | // 版权属于原作者
19 |
20 | // 发布代码于最专业的源码分享网站: Code4App.com
21 |
22 | #import "GTMBase64.h"
23 | #import "GTMDefines.h"
24 |
25 | static const char *kBase64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
26 | static const char *kWebSafeBase64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
27 | static const char kBase64PaddingChar = '=';
28 | static const char kBase64InvalidChar = 99;
29 |
30 | static const char kBase64DecodeChars[] = {
31 | // This array was generated by the following code:
32 | // #include
33 | // #include
34 | // #include
35 | // main()
36 | // {
37 | // static const char Base64[] =
38 | // "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
39 | // char *pos;
40 | // int idx, i, j;
41 | // printf(" ");
42 | // for (i = 0; i < 255; i += 8) {
43 | // for (j = i; j < i + 8; j++) {
44 | // pos = strchr(Base64, j);
45 | // if ((pos == NULL) || (j == 0))
46 | // idx = 99;
47 | // else
48 | // idx = pos - Base64;
49 | // if (idx == 99)
50 | // printf(" %2d, ", idx);
51 | // else
52 | // printf(" %2d/*%c*/,", idx, j);
53 | // }
54 | // printf("\n ");
55 | // }
56 | // }
57 | 99, 99, 99, 99, 99, 99, 99, 99,
58 | 99, 99, 99, 99, 99, 99, 99, 99,
59 | 99, 99, 99, 99, 99, 99, 99, 99,
60 | 99, 99, 99, 99, 99, 99, 99, 99,
61 | 99, 99, 99, 99, 99, 99, 99, 99,
62 | 99, 99, 99, 62/*+*/, 99, 99, 99, 63/*/ */,
63 | 52/*0*/, 53/*1*/, 54/*2*/, 55/*3*/, 56/*4*/, 57/*5*/, 58/*6*/, 59/*7*/,
64 | 60/*8*/, 61/*9*/, 99, 99, 99, 99, 99, 99,
65 | 99, 0/*A*/, 1/*B*/, 2/*C*/, 3/*D*/, 4/*E*/, 5/*F*/, 6/*G*/,
66 | 7/*H*/, 8/*I*/, 9/*J*/, 10/*K*/, 11/*L*/, 12/*M*/, 13/*N*/, 14/*O*/,
67 | 15/*P*/, 16/*Q*/, 17/*R*/, 18/*S*/, 19/*T*/, 20/*U*/, 21/*V*/, 22/*W*/,
68 | 23/*X*/, 24/*Y*/, 25/*Z*/, 99, 99, 99, 99, 99,
69 | 99, 26/*a*/, 27/*b*/, 28/*c*/, 29/*d*/, 30/*e*/, 31/*f*/, 32/*g*/,
70 | 33/*h*/, 34/*i*/, 35/*j*/, 36/*k*/, 37/*l*/, 38/*m*/, 39/*n*/, 40/*o*/,
71 | 41/*p*/, 42/*q*/, 43/*r*/, 44/*s*/, 45/*t*/, 46/*u*/, 47/*v*/, 48/*w*/,
72 | 49/*x*/, 50/*y*/, 51/*z*/, 99, 99, 99, 99, 99,
73 | 99, 99, 99, 99, 99, 99, 99, 99,
74 | 99, 99, 99, 99, 99, 99, 99, 99,
75 | 99, 99, 99, 99, 99, 99, 99, 99,
76 | 99, 99, 99, 99, 99, 99, 99, 99,
77 | 99, 99, 99, 99, 99, 99, 99, 99,
78 | 99, 99, 99, 99, 99, 99, 99, 99,
79 | 99, 99, 99, 99, 99, 99, 99, 99,
80 | 99, 99, 99, 99, 99, 99, 99, 99,
81 | 99, 99, 99, 99, 99, 99, 99, 99,
82 | 99, 99, 99, 99, 99, 99, 99, 99,
83 | 99, 99, 99, 99, 99, 99, 99, 99,
84 | 99, 99, 99, 99, 99, 99, 99, 99,
85 | 99, 99, 99, 99, 99, 99, 99, 99,
86 | 99, 99, 99, 99, 99, 99, 99, 99,
87 | 99, 99, 99, 99, 99, 99, 99, 99,
88 | 99, 99, 99, 99, 99, 99, 99, 99
89 | };
90 |
91 | static const char kWebSafeBase64DecodeChars[] = {
92 | // This array was generated by the following code:
93 | // #include
94 | // #include
95 | // #include
96 | // main()
97 | // {
98 | // static const char Base64[] =
99 | // "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
100 | // char *pos;
101 | // int idx, i, j;
102 | // printf(" ");
103 | // for (i = 0; i < 255; i += 8) {
104 | // for (j = i; j < i + 8; j++) {
105 | // pos = strchr(Base64, j);
106 | // if ((pos == NULL) || (j == 0))
107 | // idx = 99;
108 | // else
109 | // idx = pos - Base64;
110 | // if (idx == 99)
111 | // printf(" %2d, ", idx);
112 | // else
113 | // printf(" %2d/*%c*/,", idx, j);
114 | // }
115 | // printf("\n ");
116 | // }
117 | // }
118 | 99, 99, 99, 99, 99, 99, 99, 99,
119 | 99, 99, 99, 99, 99, 99, 99, 99,
120 | 99, 99, 99, 99, 99, 99, 99, 99,
121 | 99, 99, 99, 99, 99, 99, 99, 99,
122 | 99, 99, 99, 99, 99, 99, 99, 99,
123 | 99, 99, 99, 99, 99, 62/*-*/, 99, 99,
124 | 52/*0*/, 53/*1*/, 54/*2*/, 55/*3*/, 56/*4*/, 57/*5*/, 58/*6*/, 59/*7*/,
125 | 60/*8*/, 61/*9*/, 99, 99, 99, 99, 99, 99,
126 | 99, 0/*A*/, 1/*B*/, 2/*C*/, 3/*D*/, 4/*E*/, 5/*F*/, 6/*G*/,
127 | 7/*H*/, 8/*I*/, 9/*J*/, 10/*K*/, 11/*L*/, 12/*M*/, 13/*N*/, 14/*O*/,
128 | 15/*P*/, 16/*Q*/, 17/*R*/, 18/*S*/, 19/*T*/, 20/*U*/, 21/*V*/, 22/*W*/,
129 | 23/*X*/, 24/*Y*/, 25/*Z*/, 99, 99, 99, 99, 63/*_*/,
130 | 99, 26/*a*/, 27/*b*/, 28/*c*/, 29/*d*/, 30/*e*/, 31/*f*/, 32/*g*/,
131 | 33/*h*/, 34/*i*/, 35/*j*/, 36/*k*/, 37/*l*/, 38/*m*/, 39/*n*/, 40/*o*/,
132 | 41/*p*/, 42/*q*/, 43/*r*/, 44/*s*/, 45/*t*/, 46/*u*/, 47/*v*/, 48/*w*/,
133 | 49/*x*/, 50/*y*/, 51/*z*/, 99, 99, 99, 99, 99,
134 | 99, 99, 99, 99, 99, 99, 99, 99,
135 | 99, 99, 99, 99, 99, 99, 99, 99,
136 | 99, 99, 99, 99, 99, 99, 99, 99,
137 | 99, 99, 99, 99, 99, 99, 99, 99,
138 | 99, 99, 99, 99, 99, 99, 99, 99,
139 | 99, 99, 99, 99, 99, 99, 99, 99,
140 | 99, 99, 99, 99, 99, 99, 99, 99,
141 | 99, 99, 99, 99, 99, 99, 99, 99,
142 | 99, 99, 99, 99, 99, 99, 99, 99,
143 | 99, 99, 99, 99, 99, 99, 99, 99,
144 | 99, 99, 99, 99, 99, 99, 99, 99,
145 | 99, 99, 99, 99, 99, 99, 99, 99,
146 | 99, 99, 99, 99, 99, 99, 99, 99,
147 | 99, 99, 99, 99, 99, 99, 99, 99,
148 | 99, 99, 99, 99, 99, 99, 99, 99,
149 | 99, 99, 99, 99, 99, 99, 99, 99
150 | };
151 |
152 |
153 | // Tests a character to see if it's a whitespace character.
154 | //
155 | // Returns:
156 | // YES if the character is a whitespace character.
157 | // NO if the character is not a whitespace character.
158 | //
159 | GTM_INLINE BOOL IsSpace(unsigned char c) {
160 | // we use our own mapping here because we don't want anything w/ locale
161 | // support.
162 | static BOOL kSpaces[256] = {
163 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, // 0-9
164 | 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, // 10-19
165 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20-29
166 | 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 30-39
167 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 40-49
168 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 50-59
169 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 60-69
170 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 70-79
171 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 80-89
172 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 90-99
173 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 100-109
174 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 110-119
175 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 120-129
176 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 130-139
177 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 140-149
178 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 150-159
179 | 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 160-169
180 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 170-179
181 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 180-189
182 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 190-199
183 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 200-209
184 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 210-219
185 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 220-229
186 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 230-239
187 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 240-249
188 | 0, 0, 0, 0, 0, 1, // 250-255
189 | };
190 | return kSpaces[c];
191 | }
192 |
193 | // Calculate how long the data will be once it's base64 encoded.
194 | //
195 | // Returns:
196 | // The guessed encoded length for a source length
197 | //
198 | GTM_INLINE NSUInteger CalcEncodedLength(NSUInteger srcLen, BOOL padded) {
199 | NSUInteger intermediate_result = 8 * srcLen + 5;
200 | NSUInteger len = intermediate_result / 6;
201 | if (padded) {
202 | len = ((len + 3) / 4) * 4;
203 | }
204 | return len;
205 | }
206 |
207 | // Tries to calculate how long the data will be once it's base64 decoded.
208 | // Unlike the above, this is always an upperbound, since the source data
209 | // could have spaces and might end with the padding characters on them.
210 | //
211 | // Returns:
212 | // The guessed decoded length for a source length
213 | //
214 | GTM_INLINE NSUInteger GuessDecodedLength(NSUInteger srcLen) {
215 | return (srcLen + 3) / 4 * 3;
216 | }
217 |
218 |
219 | @interface GTMBase64 (PrivateMethods)
220 |
221 | +(NSData *)baseEncode:(const void *)bytes
222 | length:(NSUInteger)length
223 | charset:(const char *)charset
224 | padded:(BOOL)padded;
225 |
226 | +(NSData *)baseDecode:(const void *)bytes
227 | length:(NSUInteger)length
228 | charset:(const char*)charset
229 | requirePadding:(BOOL)requirePadding;
230 |
231 | +(NSUInteger)baseEncode:(const char *)srcBytes
232 | srcLen:(NSUInteger)srcLen
233 | destBytes:(char *)destBytes
234 | destLen:(NSUInteger)destLen
235 | charset:(const char *)charset
236 | padded:(BOOL)padded;
237 |
238 | +(NSUInteger)baseDecode:(const char *)srcBytes
239 | srcLen:(NSUInteger)srcLen
240 | destBytes:(char *)destBytes
241 | destLen:(NSUInteger)destLen
242 | charset:(const char *)charset
243 | requirePadding:(BOOL)requirePadding;
244 |
245 | @end
246 |
247 |
248 | @implementation GTMBase64
249 |
250 | //
251 | // Standard Base64 (RFC) handling
252 | //
253 |
254 | +(NSData *)encodeData:(NSData *)data {
255 | return [self baseEncode:[data bytes]
256 | length:[data length]
257 | charset:kBase64EncodeChars
258 | padded:YES];
259 | }
260 |
261 | +(NSData *)decodeData:(NSData *)data {
262 | return [self baseDecode:[data bytes]
263 | length:[data length]
264 | charset:kBase64DecodeChars
265 | requirePadding:YES];
266 | }
267 |
268 | +(NSData *)encodeBytes:(const void *)bytes length:(NSUInteger)length {
269 | return [self baseEncode:bytes
270 | length:length
271 | charset:kBase64EncodeChars
272 | padded:YES];
273 | }
274 |
275 | +(NSData *)decodeBytes:(const void *)bytes length:(NSUInteger)length {
276 | return [self baseDecode:bytes
277 | length:length
278 | charset:kBase64DecodeChars
279 | requirePadding:YES];
280 | }
281 |
282 | +(NSString *)stringByEncodingData:(NSData *)data {
283 | NSString *result = nil;
284 | NSData *converted = [self baseEncode:[data bytes]
285 | length:[data length]
286 | charset:kBase64EncodeChars
287 | padded:YES];
288 | if (converted) {
289 | result = [[NSString alloc] initWithData:converted
290 | encoding:NSASCIIStringEncoding];
291 | }
292 | return result;
293 | }
294 |
295 | +(NSString *)stringByEncodingBytes:(const void *)bytes length:(NSUInteger)length {
296 | NSString *result = nil;
297 | NSData *converted = [self baseEncode:bytes
298 | length:length
299 | charset:kBase64EncodeChars
300 | padded:YES];
301 | if (converted) {
302 | result = [[NSString alloc] initWithData:converted
303 | encoding:NSASCIIStringEncoding];
304 | }
305 | return result;
306 | }
307 |
308 | +(NSData *)decodeString:(NSString *)string {
309 | NSData *result = nil;
310 | NSData *data = [string dataUsingEncoding:NSASCIIStringEncoding];
311 | if (data) {
312 | result = [self baseDecode:[data bytes]
313 | length:[data length]
314 | charset:kBase64DecodeChars
315 | requirePadding:YES];
316 | }
317 | return result;
318 | }
319 |
320 | //
321 | // Modified Base64 encoding so the results can go onto urls.
322 | //
323 | // The changes are in the characters generated and also the result isn't
324 | // padded to a multiple of 4.
325 | // Must use the matching call to encode/decode, won't interop with the
326 | // RFC versions.
327 | //
328 |
329 | +(NSData *)webSafeEncodeData:(NSData *)data
330 | padded:(BOOL)padded {
331 | return [self baseEncode:[data bytes]
332 | length:[data length]
333 | charset:kWebSafeBase64EncodeChars
334 | padded:padded];
335 | }
336 |
337 | +(NSData *)webSafeDecodeData:(NSData *)data {
338 | return [self baseDecode:[data bytes]
339 | length:[data length]
340 | charset:kWebSafeBase64DecodeChars
341 | requirePadding:NO];
342 | }
343 |
344 | +(NSData *)webSafeEncodeBytes:(const void *)bytes
345 | length:(NSUInteger)length
346 | padded:(BOOL)padded {
347 | return [self baseEncode:bytes
348 | length:length
349 | charset:kWebSafeBase64EncodeChars
350 | padded:padded];
351 | }
352 |
353 | +(NSData *)webSafeDecodeBytes:(const void *)bytes length:(NSUInteger)length {
354 | return [self baseDecode:bytes
355 | length:length
356 | charset:kWebSafeBase64DecodeChars
357 | requirePadding:NO];
358 | }
359 |
360 | +(NSString *)stringByWebSafeEncodingData:(NSData *)data
361 | padded:(BOOL)padded {
362 | NSString *result = nil;
363 | NSData *converted = [self baseEncode:[data bytes]
364 | length:[data length]
365 | charset:kWebSafeBase64EncodeChars
366 | padded:padded];
367 | if (converted) {
368 | result = [[NSString alloc] initWithData:converted
369 | encoding:NSASCIIStringEncoding];
370 | }
371 | return result;
372 | }
373 |
374 | +(NSString *)stringByWebSafeEncodingBytes:(const void *)bytes
375 | length:(NSUInteger)length
376 | padded:(BOOL)padded {
377 | NSString *result = nil;
378 | NSData *converted = [self baseEncode:bytes
379 | length:length
380 | charset:kWebSafeBase64EncodeChars
381 | padded:padded];
382 | if (converted) {
383 | result = [[NSString alloc] initWithData:converted
384 | encoding:NSASCIIStringEncoding];
385 | }
386 | return result;
387 | }
388 |
389 | +(NSData *)webSafeDecodeString:(NSString *)string {
390 | NSData *result = nil;
391 | NSData *data = [string dataUsingEncoding:NSASCIIStringEncoding];
392 | if (data) {
393 | result = [self baseDecode:[data bytes]
394 | length:[data length]
395 | charset:kWebSafeBase64DecodeChars
396 | requirePadding:NO];
397 | }
398 | return result;
399 | }
400 |
401 | @end
402 |
403 | @implementation GTMBase64 (PrivateMethods)
404 |
405 | //
406 | // baseEncode:length:charset:padded:
407 | //
408 | // Does the common lifting of creating the dest NSData. it creates & sizes the
409 | // data for the results. |charset| is the characters to use for the encoding
410 | // of the data. |padding| controls if the encoded data should be padded to a
411 | // multiple of 4.
412 | //
413 | // Returns:
414 | // an autorelease NSData with the encoded data, nil if any error.
415 | //
416 | +(NSData *)baseEncode:(const void *)bytes
417 | length:(NSUInteger)length
418 | charset:(const char *)charset
419 | padded:(BOOL)padded {
420 | // how big could it be?
421 | NSUInteger maxLength = CalcEncodedLength(length, padded);
422 | // make space
423 | NSMutableData *result = [NSMutableData data];
424 | [result setLength:maxLength];
425 | // do it
426 | NSUInteger finalLength = [self baseEncode:bytes
427 | srcLen:length
428 | destBytes:[result mutableBytes]
429 | destLen:[result length]
430 | charset:charset
431 | padded:padded];
432 | if (finalLength) {
433 | _GTMDevAssert(finalLength == maxLength, @"how did we calc the length wrong?");
434 | } else {
435 | // shouldn't happen, this means we ran out of space
436 | result = nil;
437 | }
438 | return result;
439 | }
440 |
441 | //
442 | // baseDecode:length:charset:requirePadding:
443 | //
444 | // Does the common lifting of creating the dest NSData. it creates & sizes the
445 | // data for the results. |charset| is the characters to use for the decoding
446 | // of the data.
447 | //
448 | // Returns:
449 | // an autorelease NSData with the decoded data, nil if any error.
450 | //
451 | //
452 | +(NSData *)baseDecode:(const void *)bytes
453 | length:(NSUInteger)length
454 | charset:(const char *)charset
455 | requirePadding:(BOOL)requirePadding {
456 | // could try to calculate what it will end up as
457 | NSUInteger maxLength = GuessDecodedLength(length);
458 | // make space
459 | NSMutableData *result = [NSMutableData data];
460 | [result setLength:maxLength];
461 | // do it
462 | NSUInteger finalLength = [self baseDecode:bytes
463 | srcLen:length
464 | destBytes:[result mutableBytes]
465 | destLen:[result length]
466 | charset:charset
467 | requirePadding:requirePadding];
468 | if (finalLength) {
469 | if (finalLength != maxLength) {
470 | // resize down to how big it was
471 | [result setLength:finalLength];
472 | }
473 | } else {
474 | // either an error in the args, or we ran out of space
475 | result = nil;
476 | }
477 | return result;
478 | }
479 |
480 | //
481 | // baseEncode:srcLen:destBytes:destLen:charset:padded:
482 | //
483 | // Encodes the buffer into the larger. returns the length of the encoded
484 | // data, or zero for an error.
485 | // |charset| is the characters to use for the encoding
486 | // |padded| tells if the result should be padded to a multiple of 4.
487 | //
488 | // Returns:
489 | // the length of the encoded data. zero if any error.
490 | //
491 | +(NSUInteger)baseEncode:(const char *)srcBytes
492 | srcLen:(NSUInteger)srcLen
493 | destBytes:(char *)destBytes
494 | destLen:(NSUInteger)destLen
495 | charset:(const char *)charset
496 | padded:(BOOL)padded {
497 | if (!srcLen || !destLen || !srcBytes || !destBytes) {
498 | return 0;
499 | }
500 |
501 | char *curDest = destBytes;
502 | const unsigned char *curSrc = (const unsigned char *)(srcBytes);
503 |
504 | // Three bytes of data encodes to four characters of cyphertext.
505 | // So we can pump through three-byte chunks atomically.
506 | while (srcLen > 2) {
507 | // space?
508 | _GTMDevAssert(destLen >= 4, @"our calc for encoded length was wrong");
509 | curDest[0] = charset[curSrc[0] >> 2];
510 | curDest[1] = charset[((curSrc[0] & 0x03) << 4) + (curSrc[1] >> 4)];
511 | curDest[2] = charset[((curSrc[1] & 0x0f) << 2) + (curSrc[2] >> 6)];
512 | curDest[3] = charset[curSrc[2] & 0x3f];
513 |
514 | curDest += 4;
515 | curSrc += 3;
516 | srcLen -= 3;
517 | destLen -= 4;
518 | }
519 |
520 | // now deal with the tail (<=2 bytes)
521 | switch (srcLen) {
522 | case 0:
523 | // Nothing left; nothing more to do.
524 | break;
525 | case 1:
526 | // One byte left: this encodes to two characters, and (optionally)
527 | // two pad characters to round out the four-character cypherblock.
528 | _GTMDevAssert(destLen >= 2, @"our calc for encoded length was wrong");
529 | curDest[0] = charset[curSrc[0] >> 2];
530 | curDest[1] = charset[(curSrc[0] & 0x03) << 4];
531 | curDest += 2;
532 | destLen -= 2;
533 | if (padded) {
534 | _GTMDevAssert(destLen >= 2, @"our calc for encoded length was wrong");
535 | curDest[0] = kBase64PaddingChar;
536 | curDest[1] = kBase64PaddingChar;
537 | curDest += 2;
538 | }
539 | break;
540 | case 2:
541 | // Two bytes left: this encodes to three characters, and (optionally)
542 | // one pad character to round out the four-character cypherblock.
543 | _GTMDevAssert(destLen >= 3, @"our calc for encoded length was wrong");
544 | curDest[0] = charset[curSrc[0] >> 2];
545 | curDest[1] = charset[((curSrc[0] & 0x03) << 4) + (curSrc[1] >> 4)];
546 | curDest[2] = charset[(curSrc[1] & 0x0f) << 2];
547 | curDest += 3;
548 | destLen -= 3;
549 | if (padded) {
550 | _GTMDevAssert(destLen >= 1, @"our calc for encoded length was wrong");
551 | curDest[0] = kBase64PaddingChar;
552 | curDest += 1;
553 | }
554 | break;
555 | }
556 | // return the length
557 | return (curDest - destBytes);
558 | }
559 |
560 | //
561 | // baseDecode:srcLen:destBytes:destLen:charset:requirePadding:
562 | //
563 | // Decodes the buffer into the larger. returns the length of the decoded
564 | // data, or zero for an error.
565 | // |charset| is the character decoding buffer to use
566 | //
567 | // Returns:
568 | // the length of the encoded data. zero if any error.
569 | //
570 | +(NSUInteger)baseDecode:(const char *)srcBytes
571 | srcLen:(NSUInteger)srcLen
572 | destBytes:(char *)destBytes
573 | destLen:(NSUInteger)destLen
574 | charset:(const char *)charset
575 | requirePadding:(BOOL)requirePadding {
576 | if (!srcLen || !destLen || !srcBytes || !destBytes) {
577 | return 0;
578 | }
579 |
580 | int decode;
581 | NSUInteger destIndex = 0;
582 | int state = 0;
583 | char ch = 0;
584 | while (srcLen-- && (ch = *srcBytes++) != 0) {
585 | if (IsSpace(ch)) // Skip whitespace
586 | continue;
587 |
588 | if (ch == kBase64PaddingChar)
589 | break;
590 |
591 | decode = charset[(unsigned int)ch];
592 | if (decode == kBase64InvalidChar)
593 | return 0;
594 |
595 | // Four cyphertext characters decode to three bytes.
596 | // Therefore we can be in one of four states.
597 | switch (state) {
598 | case 0:
599 | // We're at the beginning of a four-character cyphertext block.
600 | // This sets the high six bits of the first byte of the
601 | // plaintext block.
602 | _GTMDevAssert(destIndex < destLen, @"our calc for decoded length was wrong");
603 | destBytes[destIndex] = decode << 2;
604 | state = 1;
605 | break;
606 | case 1:
607 | // We're one character into a four-character cyphertext block.
608 | // This sets the low two bits of the first plaintext byte,
609 | // and the high four bits of the second plaintext byte.
610 | _GTMDevAssert((destIndex+1) < destLen, @"our calc for decoded length was wrong");
611 | destBytes[destIndex] |= decode >> 4;
612 | destBytes[destIndex+1] = (decode & 0x0f) << 4;
613 | destIndex++;
614 | state = 2;
615 | break;
616 | case 2:
617 | // We're two characters into a four-character cyphertext block.
618 | // This sets the low four bits of the second plaintext
619 | // byte, and the high two bits of the third plaintext byte.
620 | // However, if this is the end of data, and those two
621 | // bits are zero, it could be that those two bits are
622 | // leftovers from the encoding of data that had a length
623 | // of two mod three.
624 | _GTMDevAssert((destIndex+1) < destLen, @"our calc for decoded length was wrong");
625 | destBytes[destIndex] |= decode >> 2;
626 | destBytes[destIndex+1] = (decode & 0x03) << 6;
627 | destIndex++;
628 | state = 3;
629 | break;
630 | case 3:
631 | // We're at the last character of a four-character cyphertext block.
632 | // This sets the low six bits of the third plaintext byte.
633 | _GTMDevAssert(destIndex < destLen, @"our calc for decoded length was wrong");
634 | destBytes[destIndex] |= decode;
635 | destIndex++;
636 | state = 0;
637 | break;
638 | }
639 | }
640 |
641 | // We are done decoding Base-64 chars. Let's see if we ended
642 | // on a byte boundary, and/or with erroneous trailing characters.
643 | if (ch == kBase64PaddingChar) { // We got a pad char
644 | if ((state == 0) || (state == 1)) {
645 | return 0; // Invalid '=' in first or second position
646 | }
647 | if (srcLen == 0) {
648 | if (state == 2) { // We run out of input but we still need another '='
649 | return 0;
650 | }
651 | // Otherwise, we are in state 3 and only need this '='
652 | } else {
653 | if (state == 2) { // need another '='
654 | while ((ch = *srcBytes++) && (srcLen-- > 0)) {
655 | if (!IsSpace(ch))
656 | break;
657 | }
658 | if (ch != kBase64PaddingChar) {
659 | return 0;
660 | }
661 | }
662 | // state = 1 or 2, check if all remain padding is space
663 | while ((ch = *srcBytes++) && (srcLen-- > 0)) {
664 | if (!IsSpace(ch)) {
665 | return 0;
666 | }
667 | }
668 | }
669 | } else {
670 | // We ended by seeing the end of the string.
671 |
672 | if (requirePadding) {
673 | // If we require padding, then anything but state 0 is an error.
674 | if (state != 0) {
675 | return 0;
676 | }
677 | } else {
678 | // Make sure we have no partial bytes lying around. Note that we do not
679 | // require trailing '=', so states 2 and 3 are okay too.
680 | if (state == 1) {
681 | return 0;
682 | }
683 | }
684 | }
685 |
686 | // If then next piece of output was valid and got written to it means we got a
687 | // very carefully crafted input that appeared valid but contains some trailing
688 | // bits past the real length, so just toss the thing.
689 | if ((destIndex < destLen) &&
690 | (destBytes[destIndex] != 0)) {
691 | return 0;
692 | }
693 |
694 | return destIndex;
695 | }
696 |
697 | @end
698 |
--------------------------------------------------------------------------------
/IAP/Security/GTMBase64/GTMDefines.h:
--------------------------------------------------------------------------------
1 | //
2 | // GTMDefines.h
3 | //
4 | // Copyright 2008 Google Inc.
5 | //
6 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not
7 | // use this file except in compliance with the License. You may obtain a copy
8 | // of the License at
9 | //
10 |
11 | //
12 | // Unless required by applicable law or agreed to in writing, software
13 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 | // License for the specific language governing permissions and limitations under
16 | // the License.
17 | //
18 |
19 | // 版权属于原作者
20 |
21 | // 发布代码于最专业的源码分享网站: Code4App.com
22 |
23 | // ============================================================================
24 |
25 | #include
26 | #include
27 |
28 | #if TARGET_OS_IPHONE
29 | #include
30 | #endif // TARGET_OS_IPHONE
31 |
32 | // Not all MAC_OS_X_VERSION_10_X macros defined in past SDKs
33 | #ifndef MAC_OS_X_VERSION_10_5
34 | #define MAC_OS_X_VERSION_10_5 1050
35 | #endif
36 | #ifndef MAC_OS_X_VERSION_10_6
37 | #define MAC_OS_X_VERSION_10_6 1060
38 | #endif
39 | #ifndef MAC_OS_X_VERSION_10_7
40 | #define MAC_OS_X_VERSION_10_7 1070
41 | #endif
42 |
43 | // Not all __IPHONE_X macros defined in past SDKs
44 | #ifndef __IPHONE_3_0
45 | #define __IPHONE_3_0 30000
46 | #endif
47 | #ifndef __IPHONE_3_1
48 | #define __IPHONE_3_1 30100
49 | #endif
50 | #ifndef __IPHONE_3_2
51 | #define __IPHONE_3_2 30200
52 | #endif
53 | #ifndef __IPHONE_4_0
54 | #define __IPHONE_4_0 40000
55 | #endif
56 | #ifndef __IPHONE_4_3
57 | #define __IPHONE_4_3 40300
58 | #endif
59 | #ifndef __IPHONE_5_0
60 | #define __IPHONE_5_0 50000
61 | #endif
62 |
63 | // ----------------------------------------------------------------------------
64 | // CPP symbols that can be overridden in a prefix to control how the toolbox
65 | // is compiled.
66 | // ----------------------------------------------------------------------------
67 |
68 |
69 | // By setting the GTM_CONTAINERS_VALIDATION_FAILED_LOG and
70 | // GTM_CONTAINERS_VALIDATION_FAILED_ASSERT macros you can control what happens
71 | // when a validation fails. If you implement your own validators, you may want
72 | // to control their internals using the same macros for consistency.
73 | #ifndef GTM_CONTAINERS_VALIDATION_FAILED_ASSERT
74 | #define GTM_CONTAINERS_VALIDATION_FAILED_ASSERT 0
75 | #endif
76 |
77 | // Give ourselves a consistent way to do inlines. Apple's macros even use
78 | // a few different actual definitions, so we're based off of the foundation
79 | // one.
80 | #if !defined(GTM_INLINE)
81 | #if (defined (__GNUC__) && (__GNUC__ == 4)) || defined (__clang__)
82 | #define GTM_INLINE static __inline__ __attribute__((always_inline))
83 | #else
84 | #define GTM_INLINE static __inline__
85 | #endif
86 | #endif
87 |
88 | // Give ourselves a consistent way of doing externs that links up nicely
89 | // when mixing objc and objc++
90 | #if !defined (GTM_EXTERN)
91 | #if defined __cplusplus
92 | #define GTM_EXTERN extern "C"
93 | #define GTM_EXTERN_C_BEGIN extern "C" {
94 | #define GTM_EXTERN_C_END }
95 | #else
96 | #define GTM_EXTERN extern
97 | #define GTM_EXTERN_C_BEGIN
98 | #define GTM_EXTERN_C_END
99 | #endif
100 | #endif
101 |
102 | // Give ourselves a consistent way of exporting things if we have visibility
103 | // set to hidden.
104 | #if !defined (GTM_EXPORT)
105 | #define GTM_EXPORT __attribute__((visibility("default")))
106 | #endif
107 |
108 | // Give ourselves a consistent way of declaring something as unused. This
109 | // doesn't use __unused because that is only supported in gcc 4.2 and greater.
110 | #if !defined (GTM_UNUSED)
111 | #define GTM_UNUSED(x) ((void)(x))
112 | #endif
113 |
114 | // _GTMDevLog & _GTMDevAssert
115 | //
116 | // _GTMDevLog & _GTMDevAssert are meant to be a very lightweight shell for
117 | // developer level errors. This implementation simply macros to NSLog/NSAssert.
118 | // It is not intended to be a general logging/reporting system.
119 | //
120 | // Please see
121 | // for a little more background on the usage of these macros.
122 | //
123 | // _GTMDevLog log some error/problem in debug builds
124 | // _GTMDevAssert assert if conditon isn't met w/in a method/function
125 | // in all builds.
126 | //
127 | // To replace this system, just provide different macro definitions in your
128 | // prefix header. Remember, any implementation you provide *must* be thread
129 | // safe since this could be called by anything in what ever situtation it has
130 | // been placed in.
131 | //
132 |
133 | // We only define the simple macros if nothing else has defined this.
134 | #ifndef _GTMDevLog
135 |
136 | #ifdef DEBUG
137 | #define _GTMDevLog(...) NSLog(__VA_ARGS__)
138 | #else
139 | #define _GTMDevLog(...) do { } while (0)
140 | #endif
141 |
142 | #endif // _GTMDevLog
143 |
144 | #ifndef _GTMDevAssert
145 | // we directly invoke the NSAssert handler so we can pass on the varargs
146 | // (NSAssert doesn't have a macro we can use that takes varargs)
147 | #if !defined(NS_BLOCK_ASSERTIONS)
148 | #define _GTMDevAssert(condition, ...) \
149 | do { \
150 | if (!(condition)) { \
151 | [[NSAssertionHandler currentHandler] \
152 | handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] \
153 | file:[NSString stringWithUTF8String:__FILE__] \
154 | lineNumber:__LINE__ \
155 | description:__VA_ARGS__]; \
156 | } \
157 | } while(0)
158 | #else // !defined(NS_BLOCK_ASSERTIONS)
159 | #define _GTMDevAssert(condition, ...) do { } while (0)
160 | #endif // !defined(NS_BLOCK_ASSERTIONS)
161 |
162 | #endif // _GTMDevAssert
163 |
164 | // _GTMCompileAssert
165 | // _GTMCompileAssert is an assert that is meant to fire at compile time if you
166 | // want to check things at compile instead of runtime. For example if you
167 | // want to check that a wchar is 4 bytes instead of 2 you would use
168 | // _GTMCompileAssert(sizeof(wchar_t) == 4, wchar_t_is_4_bytes_on_OS_X)
169 | // Note that the second "arg" is not in quotes, and must be a valid processor
170 | // symbol in it's own right (no spaces, punctuation etc).
171 |
172 | // Wrapping this in an #ifndef allows external groups to define their own
173 | // compile time assert scheme.
174 | #ifndef _GTMCompileAssert
175 | // We got this technique from here:
176 |
177 |
178 | #define _GTMCompileAssertSymbolInner(line, msg) _GTMCOMPILEASSERT ## line ## __ ## msg
179 | #define _GTMCompileAssertSymbol(line, msg) _GTMCompileAssertSymbolInner(line, msg)
180 | #define _GTMCompileAssert(test, msg) \
181 | typedef char _GTMCompileAssertSymbol(__LINE__, msg) [ ((test) ? 1 : -1) ]
182 | #endif // _GTMCompileAssert
183 |
184 | // ----------------------------------------------------------------------------
185 | // CPP symbols defined based on the project settings so the GTM code has
186 | // simple things to test against w/o scattering the knowledge of project
187 | // setting through all the code.
188 | // ----------------------------------------------------------------------------
189 |
190 | // Provide a single constant CPP symbol that all of GTM uses for ifdefing
191 | // iPhone code.
192 | #if TARGET_OS_IPHONE // iPhone SDK
193 | // For iPhone specific stuff
194 | #define GTM_IPHONE_SDK 1
195 | #if TARGET_IPHONE_SIMULATOR
196 | #define GTM_IPHONE_SIMULATOR 1
197 | #else
198 | #define GTM_IPHONE_DEVICE 1
199 | #endif // TARGET_IPHONE_SIMULATOR
200 | // By default, GTM has provided it's own unittesting support, define this
201 | // to use the support provided by Xcode, especially for the Xcode4 support
202 | // for unittesting.
203 | #ifndef GTM_IPHONE_USE_SENTEST
204 | #define GTM_IPHONE_USE_SENTEST 0
205 | #endif
206 | #else
207 | // For MacOS specific stuff
208 | #define GTM_MACOS_SDK 1
209 | #endif
210 |
211 | // Some of our own availability macros
212 | #if GTM_MACOS_SDK
213 | #define GTM_AVAILABLE_ONLY_ON_IPHONE UNAVAILABLE_ATTRIBUTE
214 | #define GTM_AVAILABLE_ONLY_ON_MACOS
215 | #else
216 | #define GTM_AVAILABLE_ONLY_ON_IPHONE
217 | #define GTM_AVAILABLE_ONLY_ON_MACOS UNAVAILABLE_ATTRIBUTE
218 | #endif
219 |
220 | // Provide a symbol to include/exclude extra code for GC support. (This mainly
221 | // just controls the inclusion of finalize methods).
222 | #ifndef GTM_SUPPORT_GC
223 | #if GTM_IPHONE_SDK
224 | // iPhone never needs GC
225 | #define GTM_SUPPORT_GC 0
226 | #else
227 | // We can't find a symbol to tell if GC is supported/required, so best we
228 | // do on Mac targets is include it if we're on 10.5 or later.
229 | #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
230 | #define GTM_SUPPORT_GC 0
231 | #else
232 | #define GTM_SUPPORT_GC 1
233 | #endif
234 | #endif
235 | #endif
236 |
237 | // To simplify support for 64bit (and Leopard in general), we provide the type
238 | // defines for non Leopard SDKs
239 | #if !(MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
240 | // NSInteger/NSUInteger and Max/Mins
241 | #ifndef NSINTEGER_DEFINED
242 | #if __LP64__ || NS_BUILD_32_LIKE_64
243 | typedef long NSInteger;
244 | typedef unsigned long NSUInteger;
245 | #else
246 | typedef int NSInteger;
247 | typedef unsigned int NSUInteger;
248 | #endif
249 | #define NSIntegerMax LONG_MAX
250 | #define NSIntegerMin LONG_MIN
251 | #define NSUIntegerMax ULONG_MAX
252 | #define NSINTEGER_DEFINED 1
253 | #endif // NSINTEGER_DEFINED
254 | // CGFloat
255 | #ifndef CGFLOAT_DEFINED
256 | #if defined(__LP64__) && __LP64__
257 | // This really is an untested path (64bit on Tiger?)
258 | typedef double CGFloat;
259 | #define CGFLOAT_MIN DBL_MIN
260 | #define CGFLOAT_MAX DBL_MAX
261 | #define CGFLOAT_IS_DOUBLE 1
262 | #else /* !defined(__LP64__) || !__LP64__ */
263 | typedef float CGFloat;
264 | #define CGFLOAT_MIN FLT_MIN
265 | #define CGFLOAT_MAX FLT_MAX
266 | #define CGFLOAT_IS_DOUBLE 0
267 | #endif /* !defined(__LP64__) || !__LP64__ */
268 | #define CGFLOAT_DEFINED 1
269 | #endif // CGFLOAT_DEFINED
270 | #endif // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
271 |
272 |
273 | #ifndef __has_feature // Optional.
274 | #define __has_feature(x) 0 // Compatibility with non-clang compilers.
275 | #endif
276 |
277 | #ifndef NS_RETURNS_RETAINED
278 | #if __has_feature(attribute_ns_returns_retained)
279 | #define NS_RETURNS_RETAINED __attribute__((ns_returns_retained))
280 | #else
281 | #define NS_RETURNS_RETAINED
282 | #endif
283 | #endif
284 |
285 | #ifndef NS_RETURNS_NOT_RETAINED
286 | #if __has_feature(attribute_ns_returns_not_retained)
287 | #define NS_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained))
288 | #else
289 | #define NS_RETURNS_NOT_RETAINED
290 | #endif
291 | #endif
292 |
293 | #ifndef CF_RETURNS_RETAINED
294 | #if __has_feature(attribute_cf_returns_retained)
295 | #define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
296 | #else
297 | #define CF_RETURNS_RETAINED
298 | #endif
299 | #endif
300 |
301 | #ifndef CF_RETURNS_NOT_RETAINED
302 | #if __has_feature(attribute_cf_returns_not_retained)
303 | #define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained))
304 | #else
305 | #define CF_RETURNS_NOT_RETAINED
306 | #endif
307 | #endif
308 |
309 | #ifndef NS_CONSUMED
310 | #if __has_feature(attribute_ns_consumed)
311 | #define NS_CONSUMED __attribute__((ns_consumed))
312 | #else
313 | #define NS_CONSUMED
314 | #endif
315 | #endif
316 |
317 | #ifndef CF_CONSUMED
318 | #if __has_feature(attribute_cf_consumed)
319 | #define CF_CONSUMED __attribute__((cf_consumed))
320 | #else
321 | #define CF_CONSUMED
322 | #endif
323 | #endif
324 |
325 | #ifndef NS_CONSUMES_SELF
326 | #if __has_feature(attribute_ns_consumes_self)
327 | #define NS_CONSUMES_SELF __attribute__((ns_consumes_self))
328 | #else
329 | #define NS_CONSUMES_SELF
330 | #endif
331 | #endif
332 |
333 | // Defined on 10.6 and above.
334 | #ifndef NS_FORMAT_ARGUMENT
335 | #define NS_FORMAT_ARGUMENT(A)
336 | #endif
337 |
338 | // Defined on 10.6 and above.
339 | #ifndef NS_FORMAT_FUNCTION
340 | #define NS_FORMAT_FUNCTION(F,A)
341 | #endif
342 |
343 | // Defined on 10.6 and above.
344 | #ifndef CF_FORMAT_ARGUMENT
345 | #define CF_FORMAT_ARGUMENT(A)
346 | #endif
347 |
348 | // Defined on 10.6 and above.
349 | #ifndef CF_FORMAT_FUNCTION
350 | #define CF_FORMAT_FUNCTION(F,A)
351 | #endif
352 |
353 | #ifndef GTM_NONNULL
354 | #define GTM_NONNULL(x) __attribute__((nonnull(x)))
355 | #endif
356 |
357 | #ifdef __OBJC__
358 |
359 | // Declared here so that it can easily be used for logging tracking if
360 | // necessary. See GTMUnitTestDevLog.h for details.
361 | @class NSString;
362 | GTM_EXTERN void _GTMUnitTestDevLog(NSString *format, ...);
363 |
364 | // Macro to allow you to create NSStrings out of other macros.
365 | // #define FOO foo
366 | // NSString *fooString = GTM_NSSTRINGIFY(FOO);
367 | #if !defined (GTM_NSSTRINGIFY)
368 | #define GTM_NSSTRINGIFY_INNER(x) @#x
369 | #define GTM_NSSTRINGIFY(x) GTM_NSSTRINGIFY_INNER(x)
370 | #endif
371 |
372 | // Macro to allow fast enumeration when building for 10.5 or later, and
373 | // reliance on NSEnumerator for 10.4. Remember, NSDictionary w/ FastEnumeration
374 | // does keys, so pick the right thing, nothing is done on the FastEnumeration
375 | // side to be sure you're getting what you wanted.
376 | #ifndef GTM_FOREACH_OBJECT
377 | #if TARGET_OS_IPHONE || !(MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5)
378 | #define GTM_FOREACH_ENUMEREE(element, enumeration) \
379 | for (element in enumeration)
380 | #define GTM_FOREACH_OBJECT(element, collection) \
381 | for (element in collection)
382 | #define GTM_FOREACH_KEY(element, collection) \
383 | for (element in collection)
384 | #else
385 | #define GTM_FOREACH_ENUMEREE(element, enumeration) \
386 | for (NSEnumerator *_ ## element ## _enum = enumeration; \
387 | (element = [_ ## element ## _enum nextObject]) != nil; )
388 | #define GTM_FOREACH_OBJECT(element, collection) \
389 | GTM_FOREACH_ENUMEREE(element, [collection objectEnumerator])
390 | #define GTM_FOREACH_KEY(element, collection) \
391 | GTM_FOREACH_ENUMEREE(element, [collection keyEnumerator])
392 | #endif
393 | #endif
394 |
395 | // ============================================================================
396 |
397 | // To simplify support for both Leopard and Snow Leopard we declare
398 | // the Snow Leopard protocols that we need here.
399 | #if !defined(GTM_10_6_PROTOCOLS_DEFINED) && !(MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
400 | #define GTM_10_6_PROTOCOLS_DEFINED 1
401 | @protocol NSConnectionDelegate
402 | @end
403 | @protocol NSAnimationDelegate
404 | @end
405 | @protocol NSImageDelegate
406 | @end
407 | @protocol NSTabViewDelegate
408 | @end
409 | #endif // !defined(GTM_10_6_PROTOCOLS_DEFINED) && !(MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
410 |
411 | // GTM_SEL_STRING is for specifying selector (usually property) names to KVC
412 | // or KVO methods.
413 | // In debug it will generate warnings for undeclared selectors if
414 | // -Wunknown-selector is turned on.
415 | // In release it will have no runtime overhead.
416 | #ifndef GTM_SEL_STRING
417 | #ifdef DEBUG
418 | #define GTM_SEL_STRING(selName) NSStringFromSelector(@selector(selName))
419 | #else
420 | #define GTM_SEL_STRING(selName) @#selName
421 | #endif // DEBUG
422 | #endif // GTM_SEL_STRING
423 |
424 | #endif // __OBJC__
425 |
--------------------------------------------------------------------------------
/IAP/Security/NSData+AES.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSData+AES.h
3 | // Smile
4 | //
5 | // Created by 蒲晓涛 on 12-11-24.
6 | // Copyright (c) 2012年 BOX. All rights reserved.
7 | //
8 |
9 |
10 | #import
11 |
12 | @class NSString;
13 |
14 | @interface NSData (Encryption)
15 |
16 | - (NSData *)AES128EncryptWithKey:(NSString *)key; //加密
17 | - (NSData *)AES128DecryptWithKey:(NSString *)key; //解密
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/IAP/Security/NSData+AES.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSData+AES.h
3 | // Smile
4 | //
5 | // Created by 蒲晓涛 on 12-11-24.
6 | // Copyright (c) 2012年 BOX. All rights reserved.
7 | //
8 |
9 |
10 |
11 | #import "NSData+AES.h"
12 | #import
13 | #define AESIV @"helloworld123456"
14 | //#define gIv @"0102030405060708" //可以自行修改
15 |
16 | @implementation NSData (Encryption)
17 |
18 | //(key和iv向量这里是16位的) 这里是CBC加密模式,安全性更高
19 |
20 | - (NSData *)AES128EncryptWithKey:(NSString *)key {//加密
21 | char keyPtr[kCCKeySizeAES128+1];
22 | bzero(keyPtr, sizeof(keyPtr));
23 | [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
24 |
25 | char ivPtr[kCCKeySizeAES128+1];
26 | memset(ivPtr, 0, sizeof(ivPtr));
27 | [AESIV getCString:ivPtr maxLength:sizeof(ivPtr) encoding:NSUTF8StringEncoding];
28 |
29 | NSUInteger dataLength = [self length];
30 | size_t bufferSize = dataLength + kCCBlockSizeAES128;
31 | void *buffer = malloc(bufferSize);
32 | size_t numBytesEncrypted = 0;
33 | CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt,
34 | kCCAlgorithmAES128,
35 | kCCOptionPKCS7Padding,
36 | keyPtr,
37 | kCCBlockSizeAES128,
38 | ivPtr,
39 | [self bytes],
40 | dataLength,
41 | buffer,
42 | bufferSize,
43 | &numBytesEncrypted);
44 | if (cryptStatus == kCCSuccess) {
45 | return [NSData dataWithBytesNoCopy:buffer length:numBytesEncrypted];
46 | }
47 | free(buffer);
48 | return nil;
49 | }
50 |
51 |
52 | - (NSData *)AES128DecryptWithKey:(NSString *)key {//解密
53 | char keyPtr[kCCKeySizeAES128+1];
54 | bzero(keyPtr, sizeof(keyPtr));
55 | [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
56 |
57 | char ivPtr[kCCKeySizeAES128+1];
58 | memset(ivPtr, 0, sizeof(ivPtr));
59 | [AESIV getCString:ivPtr maxLength:sizeof(ivPtr) encoding:NSUTF8StringEncoding];
60 |
61 | NSUInteger dataLength = [self length];
62 | size_t bufferSize = dataLength + kCCBlockSizeAES128;
63 | void *buffer = malloc(bufferSize);
64 | size_t numBytesDecrypted = 0;
65 | CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt,
66 | kCCAlgorithmAES128,
67 | kCCOptionPKCS7Padding,
68 | keyPtr,
69 | kCCBlockSizeAES128,
70 | ivPtr,
71 | [self bytes],
72 | dataLength,
73 | buffer,
74 | bufferSize,
75 | &numBytesDecrypted);
76 | if (cryptStatus == kCCSuccess) {
77 | return [NSData dataWithBytesNoCopy:buffer length:numBytesDecrypted];
78 | }
79 | free(buffer);
80 | return nil;
81 | }
82 |
83 | @end
84 |
--------------------------------------------------------------------------------
/IAP/Security/SecurityUtil.h:
--------------------------------------------------------------------------------
1 | //
2 | // SecurityUtil.h
3 | // Smile
4 | //
5 | // Created by 蒲晓涛 on 12-11-24.
6 | // Copyright (c) 2012年 BOX. All rights reserved.
7 | //
8 |
9 |
10 | #import
11 |
12 | @interface SecurityUtil : NSObject
13 |
14 | #pragma mark - base64
15 | + (NSString*)encodeBase64String:(NSString *)input;
16 | + (NSString*)decodeBase64String:(NSString *)input;
17 |
18 | + (NSString*)encodeBase64Data:(NSData *)data;
19 | + (NSString*)decodeBase64Data:(NSData *)data;
20 |
21 | #pragma mark - AES加密
22 | //将string转成带密码的data
23 | + (NSString*)encryptAESData:(NSString*)string app_key:(NSString*)key ;
24 | //将带密码的data转成string
25 | +(NSString*)decryptAESData:(NSData*)data app_key:(NSString*)key ;
26 |
27 |
28 | @end
29 |
--------------------------------------------------------------------------------
/IAP/Security/SecurityUtil.m:
--------------------------------------------------------------------------------
1 | //
2 | // SecurityUtil.h
3 | // Smile
4 | //
5 | // Created by 蒲晓涛 on 12-11-24.
6 | // Copyright (c) 2012年 BOX. All rights reserved.
7 | //
8 |
9 |
10 |
11 | #import "SecurityUtil.h"
12 | #import "GTMBase64.h"
13 | #import "NSData+AES.h"
14 |
15 |
16 | @implementation SecurityUtil
17 |
18 | #pragma mark - base64
19 | + (NSString*)encodeBase64String:(NSString * )input {
20 | NSData *data = [input dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
21 | data = [GTMBase64 encodeData:data];
22 | NSString *base64String = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
23 | return base64String;
24 | }
25 |
26 | + (NSString*)decodeBase64String:(NSString * )input {
27 | NSData *data = [input dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
28 | data = [GTMBase64 decodeData:data];
29 | NSString *base64String = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
30 | return base64String;
31 | }
32 |
33 | + (NSString*)encodeBase64Data:(NSData *)data {
34 | data = [GTMBase64 encodeData:data];
35 | NSString *base64String = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
36 | return base64String;
37 | }
38 |
39 | + (NSString*)decodeBase64Data:(NSData *)data {
40 | data = [GTMBase64 decodeData:data];
41 | NSString *base64String = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
42 | return base64String;
43 | }
44 |
45 | #pragma mark - AES加密
46 | //将string转成带密码的data
47 | +(NSString*)encryptAESData:(NSString*)string app_key:(NSString*)key
48 | {
49 | //将nsstring转化为nsdata
50 | NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
51 | //使用密码对nsdata进行加密
52 | NSData *encryptedData = [data AES128EncryptWithKey:key];
53 | //MYLog(@"加密后的字符串 :%@",[encryptedData base64Encoding]);
54 |
55 | return [encryptedData base64EncodedStringWithOptions:0];
56 | }
57 |
58 | #pragma mark - AES解密
59 | //将带密码的data转成string
60 | +(NSString*)decryptAESData:(NSData*)data app_key:(NSString*)key
61 | {
62 | //使用密码对data进行解密
63 | NSData *decryData = [data AES128DecryptWithKey:key];
64 |
65 | //MYLog(@"decryData is %@ ",decryData);
66 | //将解了密码的nsdata转化为nsstring
67 | NSString *str = [[NSString alloc] initWithData:decryData encoding:NSUTF8StringEncoding];
68 | return str;
69 | }
70 |
71 | @end
72 |
--------------------------------------------------------------------------------
/IAP/YYStoreKitManager.h:
--------------------------------------------------------------------------------
1 | //
2 | // CCStoreKitManager.h
3 | // IAPPaymentDemo
4 | //
5 | // Created by admin on 13-11-19.
6 | // Copyright (c) 2013年 admin. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @interface YYStoreKitManager : NSObject{
13 | int buyType;
14 | NSString* _buyProductIDTag;
15 |
16 | }
17 | @property (nonatomic, strong)NSString *receipt;
18 | @property (nonatomic, assign)NSInteger times;
19 | + (YYStoreKitManager*) sharedInstance;
20 |
21 | - (void) buy:(NSString*)buyProductIDTag;
22 | - (bool) CanMakePay;
23 | - (void) initialStore;
24 | - (void) releaseStore;
25 | - (void) requestProductData:(NSString*)buyProductIDTag;
26 | - (void) provideContent:(NSString *)product;
27 | - (void) recordTransaction:(NSString *)product;
28 |
29 | - (void) requestProUpgradeProductData:(NSString*)buyProductIDTag;
30 | - (void) paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions;
31 | - (void) purchasedTransaction: (SKPaymentTransaction *)transaction;
32 | - (void) completeTransaction: (SKPaymentTransaction *)transaction;
33 | - (void) failedTransaction: (SKPaymentTransaction *)transaction;
34 | - (void) paymentQueueRestoreCompletedTransactionsFinished: (SKPaymentTransaction *)transaction;
35 | - (void) paymentQueue:(SKPaymentQueue *) paymentQueue restoreCompletedTransactionsFailedWithError:(NSError *)error;
36 | - (void) restoreTransaction: (SKPaymentTransaction *)transaction;
37 |
38 | @end
39 |
--------------------------------------------------------------------------------
/IAP/YYStoreKitManager.m:
--------------------------------------------------------------------------------
1 | //
2 | // CCStoreKitManager.m
3 | // IAPPaymentDemo
4 | //
5 | // Created by admin on 13-11-19.
6 | // Copyright (c) 2013年 admin. All rights reserved.
7 | //
8 |
9 | #import "YYStoreKitManager.h"
10 | #import "GTMBase64.h"
11 | #import
12 | static YYStoreKitManager* _sharedInstance = nil;
13 |
14 | @implementation YYStoreKitManager
15 |
16 | +(YYStoreKitManager*)sharedInstance
17 | {
18 |
19 | if (!_sharedInstance) {
20 | _sharedInstance = [[self alloc] init];
21 |
22 | }
23 | return _sharedInstance;
24 |
25 | }
26 |
27 | +(id)alloc
28 | {
29 | @synchronized([YYStoreKitManager class])
30 | {
31 | NSAssert(_sharedInstance == nil, @"Attempted to allocate a second instance of a singleton.\n");
32 | _sharedInstance = [super alloc];
33 | return _sharedInstance;
34 | }
35 | return nil;
36 | }
37 |
38 | -(id)init {
39 | self = [super init];
40 | if (self != nil) {
41 | // initialize stuff here
42 | }
43 | return self;
44 | }
45 |
46 | -(void)initialStore
47 | {
48 | [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
49 | }
50 | -(void)releaseStore
51 | {
52 | [[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
53 | }
54 |
55 | -(void)buy:(NSString*)buyProductIDTag
56 | {
57 | [self requestProductData:buyProductIDTag];
58 | }
59 |
60 | -(bool)CanMakePay
61 | {
62 | return [SKPaymentQueue canMakePayments];
63 | }
64 |
65 | -(void)requestProductData:(NSString*)buyProductIDTag{
66 | NSLog(@"---------Request product information------------\n");
67 | _buyProductIDTag = buyProductIDTag ;
68 | NSArray *product = [[NSArray alloc] initWithObjects:buyProductIDTag,nil];
69 | NSSet *nsset = [NSSet setWithArray:product];
70 | SKProductsRequest *request=[[SKProductsRequest alloc] initWithProductIdentifiers: nsset];
71 | request.delegate=self;
72 | [request start];
73 |
74 | }
75 |
76 | #pragma argument
77 | #pragma argument SKProductsRequestDelegate
78 | - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
79 |
80 | NSLog(@"-----------Getting product information-------Yp-------%@\n",response);
81 | NSArray *myProduct = response.products;
82 | NSLog(@"Product ID:%@\n",response.invalidProductIdentifiers);
83 | NSLog(@"Product count: %lu\n", (unsigned long)[myProduct count]);
84 | // populate UI
85 | for(SKProduct *product in myProduct){
86 | NSLog(@"Detail product info\n");
87 | NSLog(@"SKProduct description: %@\n", [product description]);
88 | NSLog(@"Product localized title: %@\n" , product.localizedTitle);
89 | NSLog(@"Product localized descitption: %@\n" , product.localizedDescription);
90 | NSLog(@"Product price: %@\n" , product.price);
91 | NSLog(@"Product identifier: %@\n" , product.productIdentifier);
92 | }
93 | SKPayment *payment = nil;
94 | payment = [SKPayment paymentWithProduct:[response.products objectAtIndex:0]];
95 | NSLog(@"---------Request payment------------\n");
96 | [[SKPaymentQueue defaultQueue] addPayment:payment];
97 |
98 |
99 | }
100 | - (void)requestProUpgradeProductData:(NSString*)buyProductIDTag
101 | {
102 | NSLog(@"------Request to upgrade product data---------\n");
103 | NSSet *productIdentifiers = [NSSet setWithObject:buyProductIDTag];
104 | SKProductsRequest* productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
105 | productsRequest.delegate = self;
106 | [productsRequest start];
107 |
108 | }
109 |
110 | - (void)request:(SKRequest *)request didFailWithError:(NSError *)error
111 | {
112 | NSLog(@"-------Show fail message----------\n");
113 | NSLog(@"%@",error);
114 |
115 |
116 | }
117 |
118 | -(void) requestDidFinish:(SKRequest *)request
119 | {
120 | NSLog(@"----------Request finished--------------\n%@",request);
121 |
122 | }
123 |
124 | -(void) purchasedTransaction: (SKPaymentTransaction *)transaction
125 | {
126 | NSLog(@"-----Purchased Transaction----\n");
127 | NSArray *transactions =[[NSArray alloc] initWithObjects:transaction, nil];
128 | [self paymentQueue:[SKPaymentQueue defaultQueue] updatedTransactions:transactions];
129 |
130 | }
131 |
132 | #pragma argument
133 | #pragma argument SKPaymentTransactionObserver
134 | - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
135 | {
136 | NSLog(@"-----Payment result--------\n");
137 | for (SKPaymentTransaction *transaction in transactions)
138 | {
139 | switch (transaction.transactionState)
140 | {
141 | case SKPaymentTransactionStatePurchased:
142 | { //购买_成功
143 |
144 | self.times = 0; //向服务器验证的次数
145 | //创建请求到苹果官方进行购买验证
146 |
147 | dispatch_async(dispatch_get_global_queue(0, 0), ^{
148 |
149 | NSURL *receiptUrl=[[NSBundle mainBundle] appStoreReceiptURL];
150 | NSData *receiptData=[NSData dataWithContentsOfURL:receiptUrl];
151 | dispatch_async(dispatch_get_main_queue(), ^{
152 | NSString *receiptString=[receiptData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];//转化为base64字符串
153 | // NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:receiptData options:NSJSONReadingAllowFragments error:nil];
154 |
155 | self.receipt = receiptString;
156 | [self checkReceiptIsValid];
157 | [self completeTransaction:transaction];
158 | });
159 | });
160 |
161 | }
162 |
163 | break;
164 | case SKPaymentTransactionStateFailed: //购买_失败
165 | [self failedTransaction:transaction];
166 | NSLog(@"-----Transaction Failed--------\n");
167 | //TODO: 购买失败的提示
168 |
169 | break;
170 | case SKPaymentTransactionStateRestored:
171 | [self restoreTransaction:transaction];
172 | NSLog(@"----- Already buy this product--------\n");
173 | case SKPaymentTransactionStatePurchasing:
174 | NSLog(@"-----Transcation puchasing--------\n");
175 | break;
176 | default:
177 | break;
178 | }
179 | }
180 | }
181 | /** 验证支付结果 */
182 | -(void) checkReceiptIsValid {
183 |
184 | //就是 将本地购买之后 苹果返回的 购买凭证 发给自己后台验证, 数据比较多用post请求
185 |
186 |
187 |
188 | NSString *strUrl = @"";
189 | // strUrl = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; //ios 9之前
190 | //ios 9 之后
191 | strUrl = [strUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
192 | // 系统版本
193 | NSString *systemVersion = [[UIDevice currentDevice] systemVersion];
194 |
195 | NSDictionary *Infodic = [[NSBundle mainBundle] infoDictionary];
196 | NSString *appVersionStr = [Infodic objectForKey:@"CFBundleShortVersionString"];
197 | NSString *appBuildStr = [Infodic objectForKey:@"CFBundleVersion"];
198 | NSString *uuidStr = [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString];
199 | //platform/platform_version/app_version/app_version_num/uuid/push_id/channel/last_login_ip/lang
200 | //NSString *valuestr = [NSString stringWithFormat:@"1/%@/%@/%@/%@/%@/1/%@/en",systemVersion,appVersionStr,appBuildStr,uuidStr,tuisongma,networkOutIp];
201 | NSURLSession *session = [NSURLSession sharedSession];
202 | NSURL *url = [NSURL URLWithString:strUrl];
203 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
204 | request.HTTPMethod = @"POST";
205 |
206 | NSString *httpbodyString = [NSString stringWithFormat:@"apple_receipt=%@",self.receipt];
207 | request.HTTPBody = [httpbodyString dataUsingEncoding:NSUTF8StringEncoding];
208 | NSMutableURLRequest *mutableRequest = [request mutableCopy];
209 | [mutableRequest addValue:@"" forHTTPHeaderField:@"AGENT"];
210 | [mutableRequest addValue:@"" forHTTPHeaderField:@"AUTH"];
211 | [mutableRequest addValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
212 | request = [mutableRequest copy];
213 |
214 | NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
215 | dispatch_async(dispatch_get_main_queue(), ^{
216 |
217 | if (error) {
218 | NSLog(@"=========== error ==========");
219 | } else {
220 | NSLog(@"=========== Success =========");
221 | }
222 | });
223 |
224 | }];
225 | [dataTask resume];
226 |
227 |
228 |
229 | }
230 | - (void) completeTransaction: (SKPaymentTransaction *)transaction
231 | {
232 | NSLog(@"-----completeTransaction--------\n");
233 |
234 |
235 |
236 | // Remove the transaction from the payment queue.
237 | [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
238 |
239 | }
240 |
241 | -(void)recordTransaction:(NSString *)product
242 | {
243 | NSLog(@"-----Record transcation--------\n");
244 | // Todo: Maybe you want to save transaction result into plist.
245 | }
246 |
247 | -(void)provideContent:(NSString *)product
248 | {
249 | NSLog(@"-----Download product content--------\n");
250 | }
251 |
252 | - (void) failedTransaction: (SKPaymentTransaction *)transaction
253 | {
254 | NSLog(@"Failed\n");
255 | if (transaction.error.code != SKErrorPaymentCancelled){
256 | }
257 | [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
258 | }
259 | -(void) paymentQueueRestoreCompletedTransactionsFinished: (SKPaymentTransaction *)transaction
260 | {
261 | }
262 |
263 | - (void) restoreTransaction: (SKPaymentTransaction *)transaction
264 | {
265 | NSLog(@"-----Restore transaction--------\n");
266 | }
267 |
268 | -(void) paymentQueue:(SKPaymentQueue *) paymentQueue restoreCompletedTransactionsFailedWithError:(NSError *)error
269 | {
270 | NSLog(@"-------Payment Queue----\n");
271 | }
272 |
273 | #pragma mark connection delegate
274 | - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
275 | {
276 | NSLog(@"%@\n", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] );
277 | }
278 | - (void)connectionDidFinishLoading:(NSURLConnection *)connection
279 | {
280 |
281 | }
282 |
283 | - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
284 | {
285 | switch([(NSHTTPURLResponse *)response statusCode]) {
286 | case 200:
287 | case 206:
288 | break;
289 | case 304:
290 | break;
291 | case 400:
292 | break;
293 | case 404:
294 | break;
295 | case 416:
296 | break;
297 | case 403:
298 | break;
299 | case 401:
300 | case 500:
301 | break;
302 | default:
303 | break;
304 | }
305 | }
306 |
307 | - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
308 | {
309 | NSLog(@"test\n");
310 | }
311 |
312 |
313 |
314 | @end
315 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 MulticolourSpider
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # YY_Tool
2 | Xcode 一键导入代码块 一键调用 提高开发效率
3 |
4 | One button import code block, a key call to improve development efficiency
5 |
6 | 使用:
7 | ```
8 | cd YY_Tool
9 | ./setup_snippets.sh
10 | 成功之后输出:
11 | Done
12 | 重新新打开Xcode (需要先完全退出Xcode)
13 | ```
14 | 查看效果图:
15 | https://github.com/MulticolourSpider/YY_Tool/blob/master/result.png
16 |
17 | 
18 |
19 |
20 |
21 |
22 | { 触发 } 表示方法内触发 可利用Xcode自动补全如:YY cr
23 | 触发 { } 表示方法外触发 可利用Xcode自动补全如:YY LC
24 |
25 | 调用 | 实现 | 触发方式
26 | ---|---|---
27 | YY Button | 一键创建UIButton| { 触发 }
28 | YY TableView|一键创建UITabelView |{ 触发 }
29 | YY Label|一键创建UILabel|{ 触发 }
30 | YY Label+Custom|一键 Label自适应宽高| 触发 { }
31 | YY PickerView|一键自定义UIPickerView| { 触发 }
32 | YY Window|一键创建UIWindow |{ 触发 }
33 | YY CornerRadius| 一键设置圆角 |{ 触发 }
34 | YY Dispatch_async|一键 子 -> 主 线程(GCD)|{ 触发 }
35 | YY Timer|一键 NSTimer 带暂停/开始|{ 触发 }
36 | YY ImageView |一键 UIImageView 圆角+边框|{ 触发 }
37 | YY Switch |一键创建 UISwitch 附带 点击Action| { 触发 }
38 | YY TextField|一键创建 UITextField
自定义 清除按键 img
是否密文输入 placeholder|{ 触发 }
39 | YY ScrollView|一键创建 UIScrollView |{ 触发 }
40 | YY PageControl|一键创建 UIPageControl|{ 触发 }
41 | YY Slider|一键创建滑块 附带 值改变 拖动结束 method|{ 触发 }
42 | YY /// |一键注释|触发 { }
43 | YY interface|一键添加 interface |#import 下面 触发
44 | YY Assign|一键 声明 assign 属性 |interface 内触发
45 | YY Weak|一键 weak 属性 |interface 内触发
46 | YY Strong |一键 声明 Strong 属性 |interface 内触发
47 | YY Mark|一键 mark|触发 { }
48 | YY docPath |一键生成 documentPath|{ 触发 }
49 | YY NSNotificationCenter| 一键发送 接收通知 | { 触发 }
50 | YY ActivityIndicatorView|一键 正在加载..(菊花) 转起来 暂停|{ 触发 }
51 | YY AlertController|一键创建 警告框 附带 确定 取消 回调|{ 触发 }
52 | YY AlertController
UserNamePwdTextField|一键创建UIAlertController
附带Username/PwdTextField|{ 触发 }
53 | YY PlayMusic|一键播放音频文件 |触发 { }
54 | YY SegmentedControl
duogeyipaianjian | 一键创建一排按键 多格按键 附带点击action |{ 触发 }
55 | YY hide_keyboard |一键 点击 view 隐藏键盘| 触发 { }
56 | YY RequestDelegate|一键创建networkRequestDelegate|触发 { }
57 | YY WebView|一键创建 UIWebView 附带Delegate| { 触发 }
58 | YY Pay_IAP |一键创建 应用内支付(内购)|{ 触发 }
59 | YY AFN_网络状态改变的时候触发|一键监听网络状态:
蜂窝网络, 无网络,
wifi网络变化时触发回调| { 触发 }
60 | YY AFN_Upload |利用AFNetworking3.1.0封装的两种上传文件方式|触发 { }
61 | YY AFN_Get |一键生成 AFNetworking get 网络请求|触发 { }
62 | YY AFN_POST |一键生成 AFNetworking POST 网络请求 带进度|触发 { }
63 | YY AFN_Download |一键生成 AFNetworking Download
带下载进度 自定义存储filepath |触发 { }
64 | YY POST_yuansheng | 一键生成 ios 原生 POST 网络请求,
post 参数(可选)
自定义请求头 HTTPHeader (可选)
支持: application/x-www-form-urlencoded
multipart/form-data 两种类型 POST|{ 触发 }
65 | YY PCH|一键定义常用宏|#ifndef PrefixHeader_pch
#define PrefixHeader_pch
触发 YY PCH
#endif
66 |
67 |
68 |
69 | 删除代码块:
70 | ```
71 | cd YY_Tool
72 | ./clear_snippets.sh
73 | ```
74 | 清除Xcode 缓存垃圾,释放磁盘存储空间:
75 | ```
76 | cd YY_Tool
77 | ./clear_Temp_data.sh
78 | ```
79 | 打开代码块所在位置:
80 | ```
81 | cd YY_Tool
82 | ./open_CodeSnippets.sh
83 | ```
84 | ```
85 | 或者手动打开: Finder->前往->前往文件夹
86 | ~/Library/Developer/Xcode/UserData/CodeSnippets/
87 | ```
88 |
89 | ```
90 | 只能初始化一次 ./setup_snippets.sh
91 | 如果想要重复初始化
92 | 手动到:
93 | ~/Library/Developer/Xcode/UserData/CodeSnippets.backup/
94 | (如果上一层没有CodeSnippets文件夹 拖动到外面 如果外面有)删除CodeSnippets.backup内的CodeSnippets文件夹
95 | 然后./setup_snippets.sh
96 | ```
97 |
--------------------------------------------------------------------------------
/clear_Temp_data.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 |
3 | cd ~/Library/Developer/Xcode/DerivedData
4 | rm -rf *
5 | echo "done"
6 |
7 |
--------------------------------------------------------------------------------
/clear_snippets.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 |
3 | cd ~/Library/Developer/Xcode/UserData/CodeSnippets/
4 | rm -rf *
5 | echo "done"
6 |
7 |
--------------------------------------------------------------------------------
/open_CodeSnippets.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | open ~/Library/Developer/Xcode/UserData/CodeSnippets/
3 |
4 |
--------------------------------------------------------------------------------
/result.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MulticolourSpider/YY_Tool/8b80eaa944090bed19420249eae74a46c97698f3/result.png
--------------------------------------------------------------------------------
/setup_snippets.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | mv ~/Library/Developer/Xcode/UserData/CodeSnippets ~/Library/Developer/Xcode/UserData/CodeSnippets.backup
3 |
4 | # rm ~/Library/Developer/Xcode/UserData/CodeSnippets
5 |
6 | SRC_HOME=`pwd`
7 | ln -s ${SRC_HOME}/CodeSnippets ~/Library/Developer/Xcode/UserData/CodeSnippets
8 | echo "done"
9 |
10 |
--------------------------------------------------------------------------------