【问题标题】:ChromeCast delegates are not called when the app is in the background应用在后台时不会调用 ChromeCast 委托
【发布时间】:2015-02-13 06:15:39
【问题描述】:

我正在开发一个应用程序,我将在其中使用 ChromeCast 设备连接到电视,为了实现这一点,我在我的项目中使用了 GoogleCast FrameWork,

我的应用进入后台时遇到问题

我在这个方法中写一段代码来调用一个静音方法

- (void)applicationDidEnterBackground:(UIApplication *)application  {

    HomeViewController *lHomeViewController = [[HomeViewController alloc] init];

    _mediaControlChannel = [[GCKMediaControlChannel alloc] init];

    [lHomeViewController muteAudio];

}

它调用主视图控制器中的方法,我在其中编写了以下代码

-(void) muteAudio {

    [self.deviceManager setMuted:YES];

}

但是音频没有静音,也没有调用下面的委托方法。

- (void)mediaControlChannelDidUpdateStatus:(GCKMediaControlChannel *)mediaControlChannel

请给我建议

【问题讨论】:

  • 您正在 applicationDidEnterBackGround 中创建 HomeViewController 的新实例。您需要将 muteAudio 消息发送到正在运行的 HomeViewController 实例。

标签: ios objective-c chromecast google-cast


【解决方案1】:

您正在applicationDidEnterBackground 应用程序委托方法中创建HomeViewController 的新实例。您需要将muteAudio 消息发送到HomeViewController 的运行实例。

为此,最好的解决方案是使用NSNotificationCenter

在 HomeViewController 的 viewDidLoadviewWillAppear 方法中,使用以下行:

[[NSNotificationCenter defaultCenter] addObserver: self
                                         selector: @selector(muteAudio) 
                                             name: UIApplicationDidEnterBackgroundNotification
                                           object: nil];

这会在应用进入后台时自动调用 muteAudio 方法。

阅读更多关于 NSNotificationCenter here.

详细了解申请状态通知here

【讨论】:

    猜你喜欢
    • 2016-05-12
    • 2018-06-27
    • 1970-01-01
    • 1970-01-01
    • 2013-10-14
    • 1970-01-01
    • 1970-01-01
    • 2013-02-25
    • 2012-07-13
    相关资源
    最近更新 更多