func alertViewGosterWithBluetoothSetting (titleText:String, messageText:String, actionTitleText:String) {
let alertController = UIAlertController(title: titleText, message: messageText, preferredStyle: .Alert)
let actionButton = UIAlertAction(title: actionTitleText, style: .Default) { (_) -> Void in
let url = NSURL(string: "prefs:root=Bluetooth")
UIApplication.sharedApplication().openURL(url!)
}
let okAction = UIAlertAction(title: "İptal", style: .Default) { (_) -> Void in
self.navigationController?.popViewControllerAnimated(true)
}
alertController.addAction(actionButton)
alertController.addAction(okAction)
presentViewController(alertController, animated: true, completion: nil);
}
func peripheralManagerDidUpdateState(peripheral: CBPeripheralManager) {
var statusMessage = ""
switch peripheral.state {
case CBPeripheralManagerState.PoweredOn:
statusMessage = "Bluetooth Status: Turned On"
case CBPeripheralManagerState.PoweredOff:
statusMessage = "Bluetooth Status: Turned Off"
alertViewGosterWithBluetoothSetting("Bluetooth Kapalı", messageText: "Bluetooth kapalı olduğu için kontrol sağlayamıyoruz.", actionTitleText: "Ayarlar")
break
case CBPeripheralManagerState.Resetting:
statusMessage = "Bluetooth Status: Resetting"
case CBPeripheralManagerState.Unauthorized:
statusMessage = "Bluetooth Status: Not Authorized"
case CBPeripheralManagerState.Unsupported:
statusMessage = "Bluetooth Status: Not Supported"
default:
statusMessage = "Bluetooth Status: Unknown"
}
print(statusMessage)
if peripheral.state == CBPeripheralManagerState.PoweredOff {
//TODO: Update this property in an App Manager class
}
}
var bluetoothPeripheralMan: CBPeripheralManager?
let options = [CBCentralManagerOptionShowPowerAlertKey:0] //<-this is the magic bit!
bluetoothPeripheralMan = CBPeripheralManager(delegate: self, queue: nil, options: options)
peripheralManagerDidUpdateState(bluetoothPeripheralMan!)
class delegate yapılır. " CBPeripheralManagerDelegate "
import CoreBluetooth
Kütüphanelerden coreBluetooth eklenir.