我正面临这个奇怪的崩溃,日志对我没有多大帮助。
当我访问我的 MapViewController 应用程序时 viewDidAppear 崩溃并且日志显示了一些随机错误。
我正在使用情节提要和自动布局。在崩溃响应控制器上,我有一个全屏地图(iPad)、一堆 UI 按钮、4 个容器控制器和一个弹出框控制器。
我认为显示的错误有点随机,因为日志在界面/故事板错误上不是很准确,但这只是一个建议。
这个错误让我发疯,它随机发生,我无法弄清楚原因。有时该应用程序会连续 20 次完美地构建和运行,有时我总是会遇到错误并崩溃。
我得到的一些错误是:
error: address doesn't contain a section that points to a section in a object file
或者
Assertion failed: (scalar != 0), function -[NSISLinearExpression scaleBy:],
file /SourceCache/Foundation/Foundation-
993/Layout.subproj/IncrementalSimplex/NSISLinearExpression.m, line 244.
或者
*** Terminating app due to uncaught exception 'NSGenericException',
reason: '*** Collection <__NSSetM: 0x1f597610> was mutated while being enumerated.'
或者
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1f57d480 UIView:0x2003ffa0.trailing == UIView:0x1f579230.trailing>
Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2013-05-31 11:12:30.320 RMT Anas Plus[2543:907] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this: (1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand,
refer to the documentation for the UIView property
translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x20089640 h=--& v=--& H:[UIView:0x1f579230(748)]>",
"<NSLayoutConstraint:0x1f57d480 UIView:0x2003ffa0.trailing == UIView:0x1f579230.trailing>",
"<NSLayoutConstraint:0x1f57d400 H:|-(944)-[UIView:0x2003ffa0] (Names: '|':UIView:0x1f579230 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1f57d480 UIView:0x2003ffa0.trailing == UIView:0x1f579230.trailing>
Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
谢谢你的帮助!
编辑:
如果我已经有会话文件,我使用代码以编程方式选择我的应用程序的初始视图控制器并绕过登录窗口。
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MapView" bundle:nil];
UIViewController *viewController;
tokeN = [[LoginToken alloc]init];
NSArray *dirArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [NSString stringWithFormat:@"%@/token.json", [dirArray objectAtIndex:0]];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]==YES) {
NSData* data = [NSData dataWithContentsOfFile:path];
self.token = [[LoginToken alloc]init];
self.token = [AnasParsers createToken:data];
float timeStamp = [[NSDate date] timeIntervalSince1970];
float expiringDate = [self.token.timeStamp floatValue];
NSLog(@"now = %f expire = %f",timeStamp,expiringDate);
if (timeStamp < expiringDate) {
viewController = [storyboard instantiateViewControllerWithIdentifier:@"map"];
}
else {
[[NSFileManager defaultManager] removeItemAtPath:path error:NULL];
self.token = nil;
viewController = [storyboard instantiateViewControllerWithIdentifier:@"login"];
}
}
else {viewController = [storyboard instantiateViewControllerWithIdentifier:@"login"];}
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];