gpt4 book ai didi

ios - 如果我的 iOS 应用程序卡住了整个手机,这是否被视为操作系统本身的错误?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:05:47 26 4
gpt4 key购买 nike

我正在开发一个 iOS 应用程序,我在其中使用 AVPlayer 播放不同的 mp4 视频。大多数时候它工作正常。除了有时我的应用程序会完全卡住手机。我无法在发生这种情况的地方捕捉到它,但我认为它通常发生在这条线之后。我通过在打印 [[NSDate date] timeIntervalSince1970] 的地方放置一堆 NSLog 来验证这一点:

mylayer =[AVPlayerLayer playerLayerWithPlayer:myplayer];

卡住会持续几秒钟(有时会更长)。

即使我按下主页键或锁定键,手机也没有反应。最后我不得不按下锁定按钮大约 6-10 秒,这会硬重启整个手机。

请注意,在此期间 CPU 和内存使用率不会激增。

我知道我的代码可能有问题,但操作系统不应该足够智能,不会让单个应用程序完全卡住整个手机吗?这会被视为操作系统错误吗?如果是这样,我可能会用 Apple 记录 DTS。


****编辑:添加代码****

注意注释“//这是卡住的行”

dispatch_queue_t LOADQUEUE = dispatch_queue_create("com.yolo.LOADQUEUE", DISPATCH_QUEUE_CONCURRENT);
dispatch_async(LOADQUEUE, ^{
AVURLAsset *avAsset = [[AVURLAsset alloc] initWithURL:url options:nil];


NSLog(@"current time 4: %f",[[NSDate date] timeIntervalSince1970]);
if ([avAsset tracksWithMediaType:AVMediaTypeVideo] && [avAsset tracksWithMediaType:AVMediaTypeVideo].count>0) {
NSLog(@"current time 4.5: %f",[[NSDate date] timeIntervalSince1970]);
CGSize size = [[[avAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] naturalSize];
NSLog(@"current time 5: %f",[[NSDate date] timeIntervalSince1970]);
CGRect r = self.topHeader.frame;
r.size.height=((size.height*self.view.frame.size.width)/size.width)+self.topheaderBottomView.frame.size.height+self.topheadertopview.frame.size.height+self.itemTitle.frame.size.height;
howMuchToScrollToShowCommentButton=r.size.height;

dispatch_async(dispatch_get_main_queue(), ^{



self.topHeader.frame=r;
[UIView animateWithDuration:0 animations:^{

[self.mytableview setTableHeaderView:self.topHeader];

}completion:^(BOOL finished) {

NSArray *keys = @[@"playable"];
NSLog(@"current time 6: %f",[[NSDate date] timeIntervalSince1970]);
[avAsset loadValuesAsynchronouslyForKeys:keys completionHandler:^{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"current time 7: %f",[[NSDate date] timeIntervalSince1970]);
AVPlayerItem *newItem = [[AVPlayerItem alloc] initWithAsset:avAsset];
if (!myplayer) {
myplayer = [[AVPlayer alloc]initWithPlayerItem:newItem];
} else {
[myplayer replaceCurrentItemWithPlayerItem:newItem];
}
NSLog(@"current time 7.5: %f",[[NSDate date] timeIntervalSince1970]);
[myplayer addObserver:self forKeyPath:@"status" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:nil];
[myplayer addObserver:self forKeyPath:@"rate" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[myplayer currentItem]];
myplayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
NSLog(@"current time 7.6: %f",[[NSDate date] timeIntervalSince1970]);
mylayer =[AVPlayerLayer playerLayerWithPlayer:myplayer]; // this is the line which freezes
NSLog(@"current time 7.7: %f",[[NSDate date] timeIntervalSince1970]);


[playerView.layer addSublayer:mylayer];
mylayer.videoGravity = AVLayerVideoGravityResize;
[mylayer setFrame:playerView.bounds];
[myplayer seekToTime:kCMTimeZero];
NSLog(@"current time 8: %f",[[NSDate date] timeIntervalSince1970]);
});
}];


}];
});
} else {
NSLog(@"ITEM doesn't exist");
}
});

输出:注意时间 7.6 和 7.7 之间的 21 秒中断:

2016-06-04 01:27:20.853 XYZ[402:49072] current time 7: 1465018040.853897
2016-06-04 01:27:20.875 XYZ[402:49072] current time 7.5: 1465018040.875220
2016-06-04 01:27:20.875 XYZ[402:49072] current time 7.6: 1465018040.875871
2016-06-04 01:27:41.841 XYZ[402:49072] current time 7.7: 1465018061.841419
2016-06-04 01:27:41.841 XYZ[402:49072] current time 8: 1465018061.841863

编辑 2:

我在 xcode 中暂停了该应用程序,并查看了左侧线程正在执行的操作。这是一个屏幕截图:

enter image description here

最佳答案

这可能是通过 XCode 调试和运行的症状。你是对的,通常你应该总是能够点击主页按钮并退出应用程序。

编辑您的方案并将调试更改为发布。通过 Xcode 运行一次构建。终止应用程序,然后从设备的主屏幕启动它而不使用 Xcode。

关于ios - 如果我的 iOS 应用程序卡住了整个手机,这是否被视为操作系统本身的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37626635/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com