偷天换日之后台下载

//失去焦点调用

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

    NSURL *url =  [[NSBundle mainBundle] URLForResource:@"爸比我要喝奶奶.mp3" withExtension:nil];

   AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];

   [player prepareToPlay];

   //无限播放

    player.numberOfLoops = -1;

   [player play];

   self.player = player;

}

//进入后台调用

-(void)applicationDidEnterBackground:(UIApplication *)application

{

   //欺骗苹果 后台播放一段无声的音乐来提高 后台程序的优先级

       UIBackgroundTaskIdentifier ID =  [application beginBackgroundTaskWithExpirationHandler:^{

     //后台任务结束调用

     [application endBackgroundTask:ID];

   }];

}

你可能感兴趣的:(偷天换日之后台下载)