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);
    }
  • 相关阅读:
    FastJson中JSONObject用法
    复盘项目模板
    java Enum 类型
    Java List集合总结
    Spring boot 使用Slf4j 日志
    java.lang.reflect.UndeclaredThrowableException
    Intellij IDEA 中使用 Debug
    Java 13位时间戳转换日期格式
    Java 时间格式转换
    Spring boot 自定义注解
  • 原文地址:https://www.cnblogs.com/-ios/p/6088563.html
Copyright © 2011-2022 走看看