zoukankan      html  css  js  c++  java
  • 调用系统的提示音和振动

    调用系统的提示音和振动
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
    //        soundId = kSystemSoundID_Vibrate;//振动
     
    - (id)initSytemShake{
        self = [super init];
        if (self) {
            AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
    //        soundId = kSystemSoundID_Vibrate;//振动
        }
        return self;
    }
     
    - (id)initSytemSoundWithName:(NSString *)soundName soundType:(NSString *)soundType{
        self = [super init];
        if (self) {
            NSString * path = [NSString stringWithFormat:@"System/Library/Audio/UISounds/%@.%@",soundName,soundType];
    //        NSString *path = [[NSBundle bundleWithIdentifier:@"com.apple.UIKit"] pathForResource:soundName ofType:soundType]; //得到苹果框架资源
    //        [[NSBundle mainBundle] URLForResource:@"tap" withExtension:@"aif"];//获取自定义的声音
            if (path) {
                OSStatus error = AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &soundId);
                if (error != kAudioServicesNoError) {// 获取的声音的时候,出现错误
                    soundId = 0;
                }
                
            }
        }
        return self;
    }
     
    - (void)play{
        AudioServicesPlaySystemSound(soundId);
    }
     
    - (void)free{
        AudioServicesDisposeSystemSoundID(soundId);
    }
  • 相关阅读:
    libTIFF 图像读取与保存
    MarkDown写作之嵌入LaTeX和HTML
    R语言学习(一)前言
    Multi-Byte Character Set & Unicode Character Set
    C/C++ ShellExecuteEx调用exe可执行文件
    C/C++中相对路径与绝对路径以及斜杠与反斜杠的区别
    观察者模式
    责任链模式
    桥接模式
    void及void指针含义的深刻解析
  • 原文地址:https://www.cnblogs.com/-ios/p/6088563.html
Copyright © 2011-2022 走看看