Mac Low Energy...Developers license necessary to test? - ios

So, I am writing an app for my mac to operate as a central and connect to my iPhone as a peripheral. My iPhone is ready to receive connections and I'm working on the Mac app. When I wrote the iPhone app I found that the simulator in Xcode would not simulate the low-energy functionality and so I purchased an iOS developers license to deploy the app to my phone and test it, which solved my problem.
Now, with the mac app, I think I may be having the same problem...with one difference.
- (BOOL) isLECapableHardware
{
NSString * state = nil;
switch ([manager state])
{
case CBCentralManagerStateUnsupported:
state = #"The platform/hardware doesn't support Bluetooth Low Energy.";
NSLog(#"Central manager state: %#", state);
break;
case CBCentralManagerStateUnauthorized:
state = #"The app is not authorized to use Bluetooth Low Energy.";
NSLog(#"Central manager state: %#", state);
break;
case CBCentralManagerStatePoweredOff:
state = #"Bluetooth is currently powered off.";
NSLog(#"Central manager state: %#", state);
break;
case CBCentralManagerStatePoweredOn:
return TRUE;
case CBCentralManagerStateUnknown:
default:
state = #"Bluetooth is currently powered off.";
NSLog(#"Central manager state: %#", state);
return FALSE;
}
NSLog(#"Central manager state: %#", state);
[_textField setStringValue:state];
return false;
}
When this is called, it always falls all the way through to the default case. With the iPhone app I was falling into state unsupported while trying to test it with the simulator. Does this just mean that I need to buy a mac developers license in addition to the iOS one? Or could there be some other issue?

Related

How to convert value of Type 'CBManagerState' to expected type 'CBCentralManagerState' after conversion to Swift 3.0 syntax?

I am working on an iOS App which uses the CoreBluetooth Central Manager. The app was working as expected, until I updated to xCode 8. This update somehow forced me to convert the code from Swift 2.3 to Swift 3.0 with the conversion manager.
After this, I got the error message 'cannot convert value of Type 'CBManagerState' to expected argument type 'CBCentralManagerState' and I was searching for an answer, but due to the reason the update is new, there aren't any helpful issues or documentation regarding the CB Bluetooth used with Swift 3.0 or iOS 10.0.
The lines marked with a star are the lines which produced the error.
final class BluetoothSerial: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate {
....//some code here from HM10 Bluetooth Serial
var centralManager: CBCentralManager!
var state: CBCentralManagerState { get { return centralManager.state } *
func centralManagerDidUpdateState(_ central: CBCentralManager) {
//note that "didDisconnectPeripheral" won't be called if BLE is turned off while connected
connectedPeripheral = nil
pendingPeripheral = nil
//send it to the delegate
delegate.serialDidChangeState(central.state) *
}
}
Any help is appreciated.
Thanks in advance.
This compiles for me:
var state: CBCentralManagerState { get { return CBCentralManagerState(rawValue: centralManager.state.rawValue)! }
According to the dev forums:
The enums are binary compatible so your code will run fine on any iOS version
I'm only using the state in the
centralManagerDidUpdateState func - but doing so as follows:
switch central.state{
case .poweredOn:
NSLog("CoreBluetooth BLE hardware is powered on");
break
case .poweredOff:
NSLog("CoreBluetooth BLE hardware is powered off");
break;
case .unauthorized:
NSLog("CoreBluetooth BLE state is unauthorized");
break
case .unknown:
NSLog("CoreBluetooth BLE state is unknown");
break;
case .unsupported:
NSLog("CoreBluetooth BLE hardware is unsupported on this platform");
break;
default:
break
}
Which the compiler seems to be happy with (ie - removing the preceding CBCentralManager from CBCentralManager.poweredOn

How to detect if the user doesn't allow Apple Health Kit Authorisation?

I am using AppleHealthKit in my application. Everything is working correctly. The problem is that I am not able to detect if the user taps "Don't Allow" button when asking for permission.
With this method, my application uses HealthKit, even though the user doesn't allow this.
requestAuthorizationToShareTypes(healthKitTypesToWrite, readTypes: healthKitTypesToRead) { (success, error) -> Void in
if( completion != nil ) {
completion(success:success,error:error)
}
Apple Documentation:
So basically my question is how to detect this?
You cannot detect it, by design:
To help prevent possible leaks of sensitive health information, your app cannot determine whether a user has granted permission to read data. If you are not given permission, it simply appears as if there is no data of the requested type in the HealthKit store.
(from HKHealthStore)
You can do this but only for one specific type and only for write data(u can do the same with other type too if u have to check them)
HKHealthStore *_healthStore;
HKQuantityType *stepsType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
HKAuthorizationStatus status = [_healthStore authorizationStatusForType:stepsType];
BOOL isActive;
switch (status) {
case HKAuthorizationStatusSharingAuthorized:
isActive = YES;
break;
case HKAuthorizationStatusSharingDenied:
isActive = NO;
break;
case HKAuthorizationStatusNotDetermined:
isActive = NO;
break;
default:
break;
}
NSLog(#"STATUS-------%#", isActive ? #"yes" : #"no");

Read camera permission for iOS in Xamarin

I have an iOS app developed in Xamarin. When the app does not have permission to access the microphone, if the user tries to access the microphone from the app, I check the settings using AVAudioSession.SharedInstance().RequestRecordPermission (delegate(bool granted)) and display a message.
Now I need to do the same if the app does not have permission to access the camera. I need to check if permission is granted for camera and display a message accordingly. How can I do this?
I have got the answer. Here is what I have done:
AVCaptureDevice.RequestAccessForMediaType (AVMediaType.Video, (bool isAccessGranted) => {
//if has access
if(isAccessGranted)
{
//do something
}
//if has no access
else
{
//show an alert
}
});
Did you checked this answer?
Detect permission of camera in iOS
I think that's the solution you are looking for :).
EDIT:
Here is the highest voted answer's code ported to C#
// replace the media type to whatever you want
AVAuthorizationStatus authStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);
switch (authStatus)
{
case AVAuthorizationStatus.NotDetermined:
break;
case AVAuthorizationStatus.Restricted:
break;
case AVAuthorizationStatus.Denied:
break;
case AVAuthorizationStatus.Authorized:
break;
default:
throw new ArgumentOutOfRangeException();
}

iOS isActiveNetworkMetered api

I'm developing an iOS app which needs to know whether the cellular network is metered to save the cost, do we have an api in iOS to get the information?
In android the api is http://developer.android.com/reference/android/net/ConnectivityManager.html#isActiveNetworkMetered().
Returns if the currently active data network is metered. A network is classified as metered when the user is sensitive to heavy data usage on that connection due to monetary costs, data limitations or battery/performance issues. You should check this before doing large data transfers, and warn the user or delay the operation until another network is available.
Thanks,
James
There is no check exactly to check like network is metered or not but you can check whether the network connection is via cellular or wifi.
You can use the Reachability class provide by apple here
Then implement the following to find whether you have connected on cellular
- (BOOL)networkCheckForCellular
{
Reachability *wifiReach = [Reachability reachabilityForInternetConnection];
NetworkStatus netStatus = [wifiReach currentReachabilityStatus];
switch (netStatus)
{
case NotReachable:
{
NSLog(#"%#",#"NETWORKCHECK: Not Connected");
return false;
break;
}
case ReachableViaWiFi:
{
NSLog(#"%#",#"NETWORKCHECK: Connected Via WiFi");
return false;
break;
}
case ReachableViaWWAN:
{
NSLog(#"%#",#"NETWORKCHECK: Connected Via WWAN");
return true;
break;
}
}
return false;
}

iOS Core Bluetooth : Getting API MISUSE Warning

I am writing a test app in iOS 7 with the Core Bluetooth API. When I am testing the application I found that I am getting the following warning message:
TestBluetooth[626:60b] CoreBluetooth[API MISUSE] can only accept commands while in the powered on state
Later I debugged app and found that, warning is coming from the following line of code:
[manager scanForPeripheralsWithServices:array options:scanOptions];
So can anyone please tell me why I am getting this message in the console?
There are bluetooth 4.0 android devices around me, but this app is not discovering them as peripheral device. So why it is not discovering bluetooth 4.0 LE Android devices as peripherals?
You have to wait until the [-CBCentralManagerDelegate centralManagerDidUpdateState:] callback has been called. And then, verify that the state is PoweredOn before you start scanning for peripherals.
Please use the following code to solve the warning:
(You can reference to the code in https://github.com/luoxubin/BlueTooth4.0)
if (bluetoothPowerOn) {
[self.centralManager scanForPeripheralsWithServices:[serviceIDs copy] options:#{CBCentralManagerScanOptionAllowDuplicatesKey:#(NO)}];
}
-(void)centralManagerDidUpdateState:(CBCentralManager *)central{
switch (central.state) {
case CBManagerStatePoweredOn:
{
bluetoothPowerOn = YES; //new code
[self start];
break;
}
default:
{
bluetoothPowerOn = NO; //new code
[self stopScan:[NSError hardwareStatusErrorWithMessage:#"Cannot open Bluetooth, please check the setting." hardwareStatus:central.state]];
break;
}
}
}
Do scan when bluetooth is poweredOn:
func centralManagerDidUpdateState(_ central: CBCentralManager) {
switch central.state {
case .unknown:
print("unknown")
case .resetting:
print("resetting")
case .unsupported:
print("unsupported")
case .unauthorized:
print("unauthorized")
case .poweredOff:
print("poweredOff")
centralManager?.stopScan()
case .poweredOn:
print("poweredOn")
centralManager?.scanForPeripherals(withServices: nil, options: nil)
}
}
Just turn on my iphone Bluetooth resolve my problem. after turn on bluetooth not getting below warning.
CoreBluetooth[API MISUSE] can only accept commands while in the powered on state

Resources