ios – 丰富推送通知 – 视频无法在通知内容扩展中播放

ios – 丰富推送通知 – 视频无法在通知内容扩展中播放,第1张

概述我正在处理富通知的通知内容扩展,并且能够像下面的屏幕截图一样成功加载图像和gif: 现在我正在尝试播放视频,我正在按照代码播放它. - (void)didReceiveNotification:(UNNotification *)notification { //self.label.text = @"HELLO world";//notification.request.content. 我正在处理富通知的通知内容扩展,并且能够像下面的屏幕截图一样成功加载图像和gif:

现在我正在尝试播放视频,我正在按照代码播放它.

- (voID)dIDReceiveNotification:(UNNotification *)notification {    //self.label.text = @"HELLO world";//notification.request.content.body;    if(notification.request.content.attachments.count > 0)    {        UNNotificationAttachment *Attachen = notification.request.content.attachments.firstObject;        NSLog(@"====url %@",Attachen.URL);        AVAsset *asset = [AVAsset assetWithURL:Attachen.URL];        AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset];        AVPlayer  *player = [AVPlayer playerWithPlayerItem:item];        AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];        playerLayer.contentsGravity = AVLayerVIDeoGravityResizeAspect;        player.actionAtItemEnd = AVPlayerActionAtItemEndNone;        playerLayer.frame = CGRectMake(0,self.vIEw.frame.size.wIDth,self.vIEw.frame.size.height);            [self.VIDeoPlayerVIEw.layer addSublayer:playerLayer];        [player play];    }}

在NSLog中,我也获得了视频的文件URL.但那不会玩.如果任何人有这个解决方案,请帮助.

谢谢.

解决方法 这是我用代码做的非常小的错误.如果我执行如下代码,我们必须检查startAccessingSecurityScopedResource

- (voID)dIDReceiveNotification:(UNNotification *)notification {    if(notification.request.content.attachments.count > 0)    {            UNNotificationAttachment *Attachen = notification.request.content.attachments.firstObject;            if(Attachen.URL.startAccessingSecurityScopedResource)            {                NSLog(@"====url %@",Attachen.URL);                AVAsset *asset = [AVAsset assetWithURL:Attachen.URL];                AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset];                AVPlayer  *player = [AVPlayer playerWithPlayerItem:item];                AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];                playerLayer.contentsGravity = AVLayerVIDeoGravityResizeAspect;                player.actionAtItemEnd = AVPlayerActionAtItemEndNone;                playerLayer.frame = CGRectMake(0,self.VIDeoPlayerVIEw.frame.size.wIDth,self.VIDeoPlayerVIEw.frame.size.height);                [self.VIDeoPlayerVIEw.layer addSublayer:playerLayer];                [player play];            }                        }}

视频正在播放. Boooom …

总结

以上是内存溢出为你收集整理的ios – 丰富推送通知 – 视频无法在通知内容扩展中播放全部内容,希望文章能够帮你解决ios – 丰富推送通知 – 视频无法在通知内容扩展中播放所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1067711.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存