zoukankan      html  css  js  c++  java
  • iOS电话等中断事件的开始和结束通知

    #import "ViewController.h"
    
    #import <AVFoundation/AVFoundation.h>
    
     
    
    @interface ViewController ()
    
     
    
    @end
    
     
    
    @implementation ViewController
    
     
    
    - (void)viewDidLoad {
    
        [super viewDidLoad];
    
        // Do any additional setup after loading the view, typically from a nib.
    
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAudioSessionInterruptNoti:) name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]];
    
    }
    
    //音频播放中断的通知
    
    -(void)handleAudioSessionInterruptNoti:(NSNotification*)noti
    
    {
    
        NSDictionary *userInfo = noti.userInfo;
    
        AVAudioSessionInterruptionType type = [userInfo[AVAudioSessionInterruptionTypeKey] unsignedIntegerValue];
    
        switch (type)
    
        {
    
            case AVAudioSessionInterruptionTypeBegan:
    
            {
    
                //需要停止播放操作
    
            }
    
                break;
    
            case AVAudioSessionInterruptionTypeEnded:
    
            {
    
                AVAudioSessionInterruptionOptions options = [userInfo[AVAudioSessionInterruptionOptionKey] unsignedIntegerValue];
    
                if (options == AVAudioSessionInterruptionOptionShouldResume)
    
                {
    
                    //需要执行播放操作
    
                }
    
            }
    
                break;
    
            default:
    
                break;
    
        }
    
    }
    
     
  • 相关阅读:
    vue中的$nextTick()
    对SPA(单页面应用)的总结
    函数节流和函数防抖
    前端路由
    let、const
    深拷贝与浅拷贝
    小白浅谈Ajax基础
    关于BFC布局的那些事
    关于BFC的那些事
    Sass基础知识及语法
  • 原文地址:https://www.cnblogs.com/yuxiaoyiyou/p/8482124.html
Copyright © 2011-2022 走看看