How to make the application play audio in the background (phone shift 1.5.0 on iOS)

I have a music playback app using PhoneGap and html5 tags to play audio on iOS. Previously, it could play music perfectly in the background (using PhoneGap 1.0.0 for iOS), but after I upgraded PhoneGap to 1.5.0 (Cordova), I can no longer play in the background.

When I press the HOME button, the sound pauses. When I return to the application, it will resume.

I have already set Required background modesin Info.plistwith a value audio.

So am I missing something? Thank.

+5
source share
2 answers

In the MainController.h file, modify the following:

#import "MainViewController.h"
#import <AVFoundation/AVFoundation.h>

@implementation MainViewController

- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization

        NSError *setCategoryError = nil;
        [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryError];

    }
    return self;
}

, , (CMD + ALT + K), PhoneGap/Cordova Lib ( ) ( ) , !

: ,

+3

All Articles