zoukankan      html  css  js  c++  java
  • ios震动和播放铃声

    - (id)initSystemShake

    {

        self = [super init];

        if (self) {

            sound = kSystemSoundID_Vibrate;//震动  ipod不支持系统振动

        }

        return self;

    }

     

    - (id)initSystemSoundWithName:(NSString *)soundName SoundType:(NSString *)soundType

    {

        self = [super init];

        if (self) {

            NSString *path = [NSString stringWithFormat:@"/System/Library/Audio/UISounds/%@.%@",soundName,soundType];

            //[[NSBundle bundleWithIdentifier:@"com.apple.UIKit" ]pathForResource:soundName ofType:soundType];//得到苹果框架资源UIKit.framework ,从中取出所要播放的系统声音的路径

            //[[NSBundle mainBundle] URLForResource: @"tap" withExtension: @"aif"];  获取自定义的声音

            if (path) {

                OSStatus error = AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path],&sound);

                

    //            if (error != kAudioServicesNoError) {//获取的声音的时候,出现错误

    //                sound = nil;

    //            }

            }

        }

        return self;

    }

     

    - (void)play

    {

        AudioServicesPlaySystemSound(sound);

        //AudioServicesPlayAlertSound(sound);

    }

    - (void)playshake // 系统震动

    {

         AudioServicesPlaySystemSound(sound);

        //AudioServicesPlayAlertSound(sound);

    }

     

    - (void)dealloc

    {

        if (sound)

        {

           //AudioServicesDisposeSystemSoundID(sound);

        }

    }

     

     

     

    // --------------------点击播放-----------------

    - (IBAction)systemshake:(id)sender {

        PlaySound *sound = [[PlaySound alloc] initSystemShake];

        [sound plays];

    }

     

    - (IBAction)systemaudio:(id)sender {

        PlaySound *sound = [[PlaySound alloc] initSystemSoundWithName:@"sms-received1" SoundType:@"caf"];

        [sound play];

    }

  • 相关阅读:
    b_51_回文串划分(预处理+dp)
    b_lg_最长前缀(kmp+dfs / 优化dp)
    b_51_字符串中的最大值(next数组+倒序递推)
    b_51_凑数字(小思维+贪心)
    多测师讲解selenium(11)--定位练习题归纳_高级讲师肖sir
    多测师讲解 _ Unittest框架_高级讲师肖sir(unittest002)
    多测师讲解课堂(012) _ Unittest框架(006)_高级讲师肖sir(unittest)
    多测师讲解___测试点____高级讲师肖sir
    多测师课堂020_第一个月综合考试题 _高级讲师肖sir
    第二个月课堂011讲解selenium(001)
  • 原文地址:https://www.cnblogs.com/supersr/p/7428640.html
Copyright © 2011-2022 走看看