• 【代码笔记】iOS-调用系统震动和声音


    代码:

    RootViewController.m

    复制代码
    #import "RootViewController.h"
    #import <AudioToolbox/AudioToolbox.h>
    
    
    @interface RootViewController ()
    
    @end
    
    @implementation RootViewController
    
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        
        self.title=@"RootViewController";
        
        //这个震动不震动,有没有声音是和手机的设置一样的。
        
        //调用系统震动
        [self getChatMessageGoToShake];
        //调用系统声音
        [self getChatMessageGoToSound];
    }
    
    #pragma  -mark -调用系统震动
    - (void)getChatMessageGoToShake
    {
         //调用系统震动
         AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
    
    }
    
    #pragma -mark -调用系统声音
    - (void)getChatMessageGoToSound
    {
        //调用系统声音
        NSString *path = [NSString stringWithFormat:@"/System/Library/Audio/UISounds/%@.%@",@"sms-received3",@"caf"];
        if (path) {
            SystemSoundID sd;
            OSStatus error = AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path],&sd);
            //获取声音的时候出现错误
            if (error != kAudioServicesNoError) {
                NSLog(@"----调用系统声音出错----");
                sd = 0;
            }
            AudioServicesPlaySystemSound(sd);
        }
    }
    
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    复制代码

     

     

     
     
  • 相关阅读:
    elasticsearch 基本操作
    ElasticSearch停止启动
    oracle误删数据
    多层级sql查询
    max_result_window
    测试ik分词效果
    TransportClient 新建index,mappings dynamic_templates。
    7.10考试
    C#生成TXT文件
    C#的进度条--progressBar
  • 原文地址:https://www.cnblogs.com/yang-guang-girl/p/5156528.html
Copyright © 2020-2023  润新知