This is the 21st day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021.

preface

This article mainly records a problem about bluetooth permission being denied.

I. Bluetooth permission has been refused

1.1 in case 1

Refuse to reason

Your app declares support for bluetooth-central in the UIBackgroundModes key in your Info.plist but does not provide Bluetooth Low Energy functionality. The Bluetooth Background modes are for apps that communicate to other devices using Bluetooth Low Energy and the Core Bluetooth framework.

The real reason is that the reviewers didn’t find the bluetooth function, so they called back

Solution: The solution to be rejected due to hidden Bluetooth function in the app

1.2 case 2

Background: Based on security policy, restrict foreign access to server API, and apply for opening permissions before being rejected

Dear Mr. X,

Xx subsidiary will submit xxAPP to IOS market review on the morning of December 28, during which it will apply for lifting restrictions on foreign visits to XX (the opening time is expected to take 3-4 working days), allowing access to XX through IPv6 network (not limited to the United States, but also to other countries), so as to avoid the failure of xxAPP in IOS application market review. Hope the leader to approve, thank you!Copy the code

Reply to copy restricting Internet access

Hello, dear Audit team of Apple, we cannot log in because of our server. It has been fixed and please review again. Thank you very much!Copy the code

II. Bluetooth permission setting

  • UIBackgroundModes key tips

Bluetooth-central uses the core Bluetooth framework to communicate with surrounding BLE devices

Bluetooth-peripheral uses the core Bluetooth framework to share data

2.1 Background Execution Mode

Core Bluetooth Background Execution Modes

There are two bluetooth background modes, one for Central and the other for Peripheral. If your application requires two roles, you can declare support for both modes.

Declaration: Increment UIBackgroundModes keys and increment array values containing the following strings.

  • Bluetooth – Central — The app communicates with Bluetooth Low Energy peripherals using The Core Bluetooth framework.
  • Bluetooth-peripheral — The app shares data using The Core Bluetooth framework

The application will then be able to handle specific Bluetooth-related events in the background. Even in the background, you can still discover and connect to peripherals, and you can retrieve and read and write data. And when a CBCentralManagerDelegate or CBPeripheralDelegate delegate delegate event occurs, the system wakes up the application to handle it

It is important to note that in the background, the processing of scanning some differences: 1, CBCentralManagerScanOptionAllowDuplicatesKey this key will be ignored, many times found found the same peripheral will be merged into one event. 2. If all the apps in the scan are in the background, your app’s scan gap will be longer. As a result, it may take longer to scan the peripheral.

The idea is to reduce radiation and save power.

2.2 Supporting the mode of Peripheral background operation

To support background mode for Peripheral roles, you need to add UIBackgroundModes in the info.plist and include bluetooth-Peripheral values in the values. This wakes up the application to handle read/write and subscribe events.

The Core Bluetooth Framework not only allows your application to wake up to handle read/write and subscribe requests, but also allows your application to broadcast in background state. But you have to be aware that background broadcasting is different from foreground broadcasting. Even so, you must pay attention to the difference between background and foreground broadcast processing. Especially if your application needs to send a broadcast in the background. 1, CBAdvertisementDataLocalNameKey this key will be ignored, and peripheral local name will not be broadcast 2, CBAdvertisementDataServiceUUIDsKey values contained in all the service uuids will be put into the “overflow” area; These values are only found when the ios device display indicates that it is searched. 3. If all applications in the broadcast state are in the background, the broadcast frequency will be reduced.

2.3 Support bluetooth-Central background running mode

To enable this function, the API must be enabled to specified the “Bluetooth-central” background mode, or an error message will be displayed as follows

2019-12-20 10:02:28.602776+0800 Retail [64492:7143836] *** Terminating app due to uncaught exception'NSInternalInconsistencyException', reason: 'State restoration of CBCentralManager is only allowed for applications that have specified the "bluetooth-central" background mode'

Copy the code

Specific error messages:

2019-12-20 10:01:27.337095+0800 Retail [64492:7143836] *** Assertion Failurein-[CBCentralManager initWithDelegate:queue:options:], / BuildRoot/Library/Caches/com. Apple. XBS/Sources/MobileBluetoothFramework/MobileBluetooth - 125.10.1 / CoreBluetooth/CoreBlue Tooth/CBCentralManager. M: 203 2019-12-20 10:02:28. 537998 + 0800 retail [64492-7144702] centralManagerDidUpdateState: 5 2019-12-20 10:02:28.602776+0800 Retail [64492:7143836] *** Terminating app due to uncaught exception'NSInternalInconsistencyException', reason: 'State restoration of CBCentralManager is only allowed for applications that have specified the "bluetooth-central" background mode'*** First throw call stack: (0x18525127c 0x18442b9f8 0x18516a988 0x185c2e188 0x18acdee24 0x101dd04ac 0x101dd0370 0x1013bf968 0x1013bf8b8 0x1015c773c  0x10139cfe0 0x1b146f7c4 0x1b13d0e90 0x1b146f7c4 0x1b1470128 0x1b1396da4 0x1b139f934 0x1b139ac04 0x1b1492cc8 0x1b1a1edec  0x1b1a0d93c 0x1b1a3a7ac 0x1851e25f8 0x1851dd320 0x1851dd89c 0x1851dd0b0 0x1873dd79c 0x1b1a13978 0x1016f45ac 0x184ca28e0) libc++abi.dylib: terminating with uncaught exception oftype NSException
(lldb) c

Copy the code

2.4 CONFIGURATION of UIBackgroundModes

  1. Added the Bluetooth-central keyword to info.plist to implement the central role in UIBackgroundModes.

The Core Bluetooth framework allows your app to run in the background to perform some central Bluetooth-related tasks. While your app is in the background, you can still search and connect to peripheral devices, communicate with them, and exchange data. In addition, the system will wake up your app whenever any of the CBCentralManagerDelegate or CBPeripheralDelegate callback methods are called, allowing your app to handle important central role events, such as a sudden disconnection, peripheral roles reporting data, The status of the center manager has changed.

CBCentralManagerScanOptionAllowDuplicatesKey search options will be ignored, the multiple scan results will be combined into the same events

Initialize CBCentralManager

        / / / / CBCentralManagerOptionShowPowerAlertKey: initialization if bluetooth didn't open the prompt dialog box will appear
        / / CBCentralManagerOptionRestoreIdentifierKey: killed used in process of bluetooth connection is restored

        _centralmanager =[[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_global_queue(0.0) options:@{CBCentralManagerOptionShowPowerAlertKey      : [NSNumber numberWithBool:YES]}];

Copy the code

Use these tips to use, you need to call connectPeripheral: options: method is introduced to the following parameters. CBConnectPeripheralOptionNotifyOnConnectionKey: after the application hangs, establish connection with the specified peripheral success, has issued a circular, for printing operations? CBConnectPeripheralOptionNotifyOnDisconnectionKey: after the application hangs, if the specified peripheral disconnected, has issued a circular, to reconnect? CBConnectPeripheralOptionNotifyOnNotificationKey: after the application hangs, the specified peripheral have any notice to be prompt

  1. Bluetooth peripheral background execution mode: Bluetooth-Periphral

To work in the background as a peripheral character, you need to add Bluetoot-periphral to the info.plist file under the UIBackgroundModes keyword. When you do this, the system will wake up your app when it needs to read, write, or subscribe to events. In addition to the central read/write subscription that the app can wake up in the background to handle the connection. The Bluetooth Central library also allows your apps to broadcast in the background.

CBAdvertisementDataLocalNameKey advertising key is neglected, and the local name will not be broadcast So the service CBAdvertisementDataServiceUUIDsKey UUID is placed on a “overflow” area, They can only be found on explicitly searched iOS devices.

see also

More content please pay attention to # applets: iOS Reverse, only to present valuable information for you, focus on mobile technology research field; For more services and advice, please follow # publicid: iOS Reverse.