Swift(十六):系统的服务调用(振动,声音)

这个功能无法截图将就着看吧,多谅解;

//
//  ViewController.swift
//  systemDevice
//
//  Created by HMC on 2016/10/20.
//  Copyright © 2016年 HMC. All rights reserved.
//

import UIKit
import AudioToolbox

class ViewController: UIViewController {
    var sysID:SystemSoundID = 0
    
    /**
     振动
     
     - parameter sender: sender description
     */
    @IBAction func shake(sender: AnyObject) {
        
        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
        
    }
    /**
     响铃
     
     - parameter sender: sender description
     */
    @IBAction func ring(sender: AnyObject) {
        
        AudioServicesPlayAlertSound(sysID)
        
    }
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        //预先加载
        let path = NSBundle.mainBundle().pathForResource("ring", ofType: "wav")
        AudioServicesCreateSystemSoundID(NSURL(fileURLWithPath: path!), &sysID)
    }
    
    deinit{
        
        //注意释放 service
        AudioServicesDisposeSystemSoundID(sysID)
    }
    
}

你可能感兴趣的:(Swift(十六):系统的服务调用(振动,声音))