-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2. 增加 KVC Crash 防护测试相关
- Loading branch information
杨世超
committed
Sep 4, 2019
1 parent
84b04f8
commit a6f8780
Showing
39 changed files
with
1,235 additions
and
170 deletions.
There are no files selected for viewing
216 changes: 180 additions & 36 deletions
216
YSC-Avoid-Crash/YSC-Avoid-Crash.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r"> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" colorMatched="YES" initialViewController="BYZ-38-t0r"> | ||
<device id="retina6_1" orientation="portrait"> | ||
<adaptation id="fullscreen"/> | ||
</device> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/> | ||
<capability name="Safe area layout guides" minToolsVersion="9.0"/> | ||
<deployment identifier="iOS"/> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<scenes> | ||
<!--View Controller--> | ||
<scene sceneID="tne-QT-ifu"> | ||
<objects> | ||
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="" sceneMemberID="viewController"> | ||
<viewController id="BYZ-38-t0r" customClass="ViewController" sceneMemberID="viewController"> | ||
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC"> | ||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> | ||
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | ||
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/> | ||
</view> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="31.739999999999998" y="80.640000000000001"/> | ||
</scene> | ||
</scenes> | ||
</document> |
15 changes: 15 additions & 0 deletions
15
YSC-Avoid-Crash/YSC-Avoid-Crash/Examples/Base/BaseDefine.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// BaseDefine.h | ||
// YSC-Avoid-Crash | ||
// | ||
// Created by WalkingBoy on 2019/9/4. | ||
// Copyright © 2019 bujige. All rights reserved. | ||
// | ||
|
||
#ifndef BaseDefine_h | ||
#define BaseDefine_h | ||
|
||
#define UIScreenWidth ([[UIScreen mainScreen] bounds].size.width) | ||
#define UIScreenHeigh ([[UIScreen mainScreen] bounds].size.height) | ||
|
||
#endif /* BaseDefine_h */ |
20 changes: 20 additions & 0 deletions
20
YSC-Avoid-Crash/YSC-Avoid-Crash/Examples/Base/BaseViewController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// BaseViewController.h | ||
// YSC-Avoid-Crash | ||
// | ||
// Created by WalkingBoy on 2019/9/4. | ||
// Copyright © 2019 bujige. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import "BaseDefine.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface BaseViewController : UIViewController | ||
|
||
- (void)redirectSTD:(int)fd; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
92 changes: 92 additions & 0 deletions
92
YSC-Avoid-Crash/YSC-Avoid-Crash/Examples/Base/BaseViewController.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// | ||
// BaseViewController.m | ||
// YSC-Avoid-Crash | ||
// | ||
// Created by WalkingBoy on 2019/9/4. | ||
// Copyright © 2019 bujige. All rights reserved. | ||
// | ||
|
||
#import "BaseViewController.h" | ||
|
||
@interface BaseViewController () | ||
|
||
/* <#注释#> */ | ||
@property (nonatomic, strong) UIButton *backButton; | ||
|
||
/* <#注释#> */ | ||
@property (nonatomic, strong) UITextView *logTextView; | ||
@end | ||
|
||
@implementation BaseViewController | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
|
||
self.view.backgroundColor = [UIColor whiteColor]; | ||
[self.view addSubview:self.backButton]; | ||
[self.view addSubview:self.logTextView]; | ||
|
||
[self redirectSTD:STDOUT_FILENO]; | ||
[self redirectSTD:STDERR_FILENO]; | ||
} | ||
|
||
/** | ||
* backButton初始化 | ||
*/ | ||
- (UIButton *)backButton { | ||
if (!_backButton) { | ||
_backButton = [UIButton buttonWithType:UIButtonTypeCustom]; | ||
_backButton.frame = CGRectMake(15, 12, 44, 40); | ||
_backButton.contentMode = UIViewContentModeLeft; | ||
[_backButton setTitle:@"返回" forState:UIControlStateNormal]; | ||
[_backButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; | ||
[_backButton addTarget:self action:@selector(backButtonClick:) forControlEvents:UIControlEventTouchUpInside]; | ||
} | ||
return _backButton; | ||
} | ||
|
||
- (void)backButtonClick:(UIButton *)button { | ||
[self dismissViewControllerAnimated:YES completion:nil]; | ||
} | ||
|
||
/** | ||
* logTextView初始化 | ||
*/ | ||
- (UITextView *)logTextView { | ||
if (!_logTextView) { | ||
_logTextView = [[UITextView alloc] initWithFrame:CGRectMake(30, UIScreenHeigh-170, UIScreenWidth-60, 150)]; | ||
[_logTextView setEditable:NO]; | ||
[_logTextView setBackgroundColor:[UIColor lightGrayColor]]; | ||
[_logTextView setTextColor:[UIColor blackColor]]; | ||
[_logTextView setFont:[UIFont systemFontOfSize:15]]; | ||
} | ||
return _logTextView; | ||
} | ||
|
||
|
||
- (void)redirectNotificationHandle:(NSNotification *)nf{ // 通知方法 | ||
NSData *data = [[nf userInfo] objectForKey:NSFileHandleNotificationDataItem]; | ||
NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; | ||
|
||
self.logTextView.text = [NSString stringWithFormat:@"%@\n\n%@",self.logTextView.text, str]; // logTextView 就是要将日志输出的视图(UITextView) | ||
NSRange range; | ||
range.location = [self.logTextView.text length] - 1; | ||
range.length = 0; | ||
[self.logTextView scrollRangeToVisible:range]; | ||
[[nf object] readInBackgroundAndNotify]; | ||
} | ||
|
||
- (void)redirectSTD:(int)fd { | ||
NSPipe * pipe = [NSPipe pipe] ;// 初始化一个NSPipe 对象 | ||
NSFileHandle *pipeReadHandle = [pipe fileHandleForReading] ; | ||
dup2([[pipe fileHandleForWriting] fileDescriptor], fd) ; | ||
|
||
[[NSNotificationCenter defaultCenter] addObserver:self | ||
selector:@selector(redirectNotificationHandle:) | ||
name:NSFileHandleReadCompletionNotification | ||
object:pipeReadHandle]; // 注册通知 | ||
[pipeReadHandle readInBackgroundAndNotify]; | ||
} | ||
|
||
|
||
@end |
15 changes: 15 additions & 0 deletions
15
YSC-Avoid-Crash/YSC-Avoid-Crash/Examples/Containers/TestContainersVC.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// TestContainersVC.h | ||
// YSC-Avoid-Crash | ||
// | ||
// Created by WalkingBoy on 2019/9/4. | ||
// Copyright © 2019 bujige. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import "BaseViewController.h" | ||
|
||
@interface TestContainersVC : BaseViewController | ||
|
||
@end | ||
|
32 changes: 32 additions & 0 deletions
32
YSC-Avoid-Crash/YSC-Avoid-Crash/Examples/Containers/TestContainersVC.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// TestContainersVC.m | ||
// YSC-Avoid-Crash | ||
// | ||
// Created by WalkingBoy on 2019/9/4. | ||
// Copyright © 2019 bujige. All rights reserved. | ||
// | ||
|
||
#import "TestContainersVC.h" | ||
|
||
@interface TestContainersVC () | ||
|
||
@end | ||
|
||
@implementation TestContainersVC | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
// Do any additional setup after loading the view. | ||
} | ||
|
||
/* | ||
#pragma mark - Navigation | ||
// In a storyboard-based application, you will often want to do a little preparation before navigation | ||
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { | ||
// Get the new view controller using [segue destinationViewController]. | ||
// Pass the selected object to the new view controller. | ||
} | ||
*/ | ||
|
||
@end |
21 changes: 21 additions & 0 deletions
21
YSC-Avoid-Crash/YSC-Avoid-Crash/Examples/KVC/KVCCrashObject.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// KVCCrashObject.h | ||
// YSC-Avoid-Crash | ||
// | ||
// Created by WalkingBoy on 2019/8/28. | ||
// Copyright © 2019 bujige. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface KVCCrashObject : NSObject | ||
|
||
@property (nonatomic, copy) NSString *name; | ||
|
||
@property (nonatomic, assign) NSInteger age; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
13 changes: 13 additions & 0 deletions
13
YSC-Avoid-Crash/YSC-Avoid-Crash/Examples/KVC/KVCCrashObject.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// KVCCrashObject.m | ||
// YSC-Avoid-Crash | ||
// | ||
// Created by WalkingBoy on 2019/8/28. | ||
// Copyright © 2019 bujige. All rights reserved. | ||
// | ||
|
||
#import "KVCCrashObject.h" | ||
|
||
@implementation KVCCrashObject | ||
|
||
@end |
15 changes: 15 additions & 0 deletions
15
YSC-Avoid-Crash/YSC-Avoid-Crash/Examples/KVC/TestKVCCrashVC.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// TestKVCCrashVC.h | ||
// YSC-Avoid-Crash | ||
// | ||
// Created by WalkingBoy on 2019/9/4. | ||
// Copyright © 2019 bujige. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import "BaseViewController.h" | ||
|
||
@interface TestKVCCrashVC : BaseViewController | ||
|
||
@end | ||
|
Oops, something went wrong.