2009-04-29 46 views
0

我刚刚开发了一款iPhone音频流应用程序......现在它可以播放音频文件没有任何问题..当iPhone网络从3G切换到WiFi和反之亦然时,问题出现了。我需要在网络切换时暂停流,但当网络来临时我无法恢复播放。任何人都可以指示我如何使用代码处理这种情况?如何处理iPhone中的网络切换?

问候, SYAM小号

回答

3

您可能您的应用程序设置为check Reachability status,然后发送一个“暂停” NSNotification当网络状态变化和网络不可达(和,同样,一个“玩” NSNotification当网络状态的变化,并且现在网络又可达):

[[Reachability sharedReachability] setNetworkStatusNotificationsEnabled:YES]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:@"kNetworkReachabilityChangedNotification" object:nil]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pauseStreaming:) name:@"kPauseAudioStreamingIfPlaying" object:nil]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pauseStreaming:) name:@"kPlayAudioStreamingIfPaused" object:nil]; 

- (void) reachabilityChanged:(id)sender { 
    NetworkStatus reachabilityStatus = [[Reachability sharedReachability] internetConnectionStatus]; 
    if (reachabilityStatus == NotReachable) 
    [[NSNotificationCenter defaultCenter] postNotificationName:@"kPauseAudioStreamingIfPlaying" object:nil]; 
    else 
    [[NSNotificationCenter defaultCenter] postNotificationName:@"kPlayAudioStreamingIfPaused" object:nil]; 
} 
+0

嗨亚历克斯, 感谢您reply..I正在使用CFNetwork的框架,用于读取流bytes..Whenever任何错误发生readstream呼叫功能可以不会被解雇。因此我无法恢复比赛。 。你知道如何重置readstream回调来获取流数据吗? – 2009-04-29 06:50:15