请选择 进入手机版 | 继续访问电脑版
  • 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-12-13 16:57:28 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在开发一个 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" optionsNSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:nil];
                                [myplayer addObserver:self forKeyPath"rate" optionsNSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:nil];
                                [[NSNotificationCenter defaultCenter] addObserver:self
                                                                         selectorselector(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



Best Answer-推荐答案


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

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

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

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap