我已准备好应用程序,但我仍然坚持要添加代码以使铃声无声。当我按下按钮时会发送通知,但我想将铃声音量调为0.这是我的代码。我也很困惑在哪里放这个代码。
import UIKit
import MapKit
protocol AddViewControllerDelegate {
func addViewController(controller: AddViewController, didAddCoordinate coordinate: CLLocationCoordinate2D, radius: Double, identifier: String, note: String, eventType: EventType)
}
class AddViewController: UITableViewController {
@IBOutlet var addButton: UIBarButtonItem!
@IBOutlet var zoomButton: UIBarButtonItem!
@IBOutlet weak var eventTypeSegmentedControl: UISegmentedControl!
@IBOutlet weak var radiusTextField: UITextField!
@IBOutlet weak var noteTextField: UITextField!
@IBOutlet weak var mapView: MKMapView!
var delegate: AddViewControllerDelegate?
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.rightBarButtonItems = [addButton, zoomButton]
addButton.isEnabled = false
}
@IBAction func textFieldEditingChanged(sender: UITextField) {
addButton.isEnabled = !radiusTextField.text!.isEmpty && !noteTextField.text!.isEmpty
}
@IBAction func onCancel(sender: AnyObject) {
dismiss(animated: true, completion: nil)
}
@IBAction private func onAdd(sender: AnyObject) {
let coordinate = mapView.centerCoordinate
let radius = Double(radiusTextField.text!) ?? 0
let identifier = NSUUID().uuidString
let note = noteTextField.text
let eventType: EventType = (eventTypeSegmentedControl.selectedSegmentIndex == 0) ? .onEntry : .onExit
delegate?.addViewController(controller: self, didAddCoordinate: coordinate, radius: radius, identifier: identifier, note: note!, eventType: eventType)
}
@IBAction private func onZoomToCurrentLocation(sender: AnyObject) {
mapView.zoomToUserLocation()
}
}