我最近将我的设备从 8.1 升级到 iOS 8.3。当我的应用程序设置为 8.1 版时,我的应用程序在设备上运行良好,但现在升级后它就死机了。
我调试并找出它卡住的时间和原因。
我有 5 个容量为 50 的数组,每个数组包含从不同位置(ble、gps、视频)接收的字符串。
当 NSArray
达到它的容量时,我将所有内容写入文件并从 NSArray
中删除所有对象。我有一个 UIButton
,当它被按下时,我开始将数据收集到 NSArray
并将其写入文件 -> 那就是它卡住的时候!
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:fileName];
//check if file exisits, if not creates one.
if(![[NSFileManager defaultManager]fileExistsAtPath:filePath])
{
[[NSFileManager defaultManager] createFileAtPath:filePath contents:nil attributes:nil];
}
//writes and adds data the content to the specifec file.
NSFileHandle *fileHandler = [NSFileHandle fileHandleForUpdatingAtPath:filePath];
[fileHandler seekToEndOfFile];
[fileHandler writeData:[content dataUsingEncoding:NSUTF8StringEncoding]];
[fileHandler closeFile];
为什么设备的升级版本会对我的应用产生这种影响?
编辑: 尽管设备已卡住,但控制台日志似乎仍在运行(我让他打印他目前正在执行的功能)。
最佳答案
正如 Ashwin 所建议的那样,我将我的 Activity 移到了后台线程并且效果很好!
关于ios - 将我的设备升级到 iOS 8.3 后,我的应用程序卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30973896/