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];

    }

  • 相关阅读:
    每日总结
    每日总结
    Panda Global要点聚焦,中国应加快布局迎接区块链发展升温
    Panda Global热点关注,区块链在物流行业的应用
    Panda 交易所为你解读,区块链提速有望推动数字经济更广阔发展
    Panda 交易所视点观察,金融场景区块链应用进程已经不可逆转
    Panda 交易所焦点观察,区块链技术在各国政府管理中的运用
    Panda 交易所前沿解读,完善顶层设计 构筑区块链创新创业人才高地
    Panda 交易所热点关注,支持区块链技术发展 赋能数字经济
    区块链技术会给我们的生活带来哪些影响?Panda Global 带你一文看懂!
  • 原文地址:https://www.cnblogs.com/supersr/p/7428640.html
Copyright © 2011-2022 走看看