在背景中播放电台

我只需要确认iPhone应用程序是否可以在后台播放或流式传输。 我创建了一个工作正常的无线电应用程序。 我想添加一个功能,用户可以通过该功能在后台进程中播放广播,即他们不必保持应用程序打开以播放广播。 他们可以关闭应用程序,收音机仍在播放。 我很久以前就读过Apple有一个私有API,应用程序可以在后台运行无线电,但由于它是私有的,我不能使用它。 有什么建议?     
已邀请:
iOS SDK应高于4.0; 首先在您的代理代码中:
- (void)applicationDidEnterBackground:(UIApplication *)application {

    if (isAbove4_0)

 {

        CTCallCenter *_center = [[CTCallCenter alloc] init];

        _center.callEventHandler = ^(CTCall *call) 
       {

            //NSLog(@"call:%@", call.callState);
            if ([call.callState isEqualToString:CTCallStateIncoming]) 

                {

                [RadioPlayer pausePlayer];

        }           
    };
    }

}
然后, 我用过MPMoviePlayerController,AVPlayer也行;
if (isAbove4_0) {
    if (_mpmovieplayer == nil) {
        _mpmovieplayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
        [_mpmovieplayer setMovieControlMode:MPMovieControlModeHidden];
    }

    [_mpmovieplayer setContentURL:url];
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    [[AVAudioSession sharedInstance] setActive: YES error: nil];
    // This is necessary if you want to play a sequence of songs, otherwise your app will be
    // killed after the first one finishes.
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

    UIBackgroundTaskIdentifier newTaskId = UIBackgroundTaskInvalid;

    [_mpmovieplayer play];

    newTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
    if (newTaskId != UIBackgroundTaskInvalid && bgTaskId != UIBackgroundTaskInvalid)
        [[UIApplication sharedApplication] endBackgroundTask: bgTaskId];
    bgTaskId = newTaskId;

}
PS:我的英语很差,我希望这对你有帮助:)     
您可以使用其中一个音频流媒体在后台播放 https://github.com/mattgallagher/AudioStreamer https://github.com/DigitalDJ/AudioStreamer 它可能会帮助你。     
这就是它对我有用的方式。 在app-info.plist文件中添加以下内容
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
然后在application:didFinishLaunchingWithOptions中添加以下内容
UIBackgroundTaskIdentifier backgroundTask = [application beginBackgroundTaskWithExpirationHandler:^{
     /* just fail if this happens. */
     NSLog(@"BackgroundTask Expiration Handler is called");
     [application endBackgroundTask:backgroundTask];
}];
    

要回复问题请先登录注册