Class CBPeripheralManager

  • All Implemented Interfaces:
    NSObject

    public class CBPeripheralManager
    extends CBManager
    CBPeripheralManager The CBPeripheralManager class is an abstraction of the Peripheral and Broadcaster GAP roles, and the GATT Server role. Its primary function is to allow you to manage published services within the GATT database, and to advertise these services to other devices. Each application has sandboxed access to the shared GATT database. You can add services to the database by calling {@link addService:}; they can be removed via {@link removeService:} and removeAllServices(), as appropriate. While a service is in the database, it is visible to and can be accessed by any connected GATT Client. However, applications that have not specified the "bluetooth-peripheral" background mode will have the contents of their service(s) "disabled" when in the background. Any remote device trying to access characteristic values or descriptors during this time will receive an error response. Once you've published services that you want to share, you can ask to advertise their availability and allow other devices to connect to you by calling {@link startAdvertising:}. Like the GATT database, advertisement is managed at the system level and shared by all applications. This means that even if you aren't advertising at the moment, someone else might be!
    • Constructor Detail

      • CBPeripheralManager

        protected CBPeripheralManager​(org.moe.natj.general.Pointer peer)
    • Method Detail

      • accessInstanceVariablesDirectly

        public static boolean accessInstanceVariablesDirectly()
      • allocWithZone

        public static java.lang.Object allocWithZone​(org.moe.natj.general.ptr.VoidPtr zone)
      • authorizationStatus

        public static long authorizationStatus()
        authorizationStatus This method does not prompt the user for access. You can use it to detect restricted access and simply hide UI instead of prompting for access.
        Returns:
        The current authorization status for sharing data while backgrounded. For the constants returned, see CBPeripheralManagerAuthorizationStatus.
        See Also:
        CBPeripheralManagerAuthorizationStatus
      • automaticallyNotifiesObserversForKey

        public static boolean automaticallyNotifiesObserversForKey​(java.lang.String key)
      • cancelPreviousPerformRequestsWithTarget

        public static void cancelPreviousPerformRequestsWithTarget​(java.lang.Object aTarget)
      • cancelPreviousPerformRequestsWithTargetSelectorObject

        public static void cancelPreviousPerformRequestsWithTargetSelectorObject​(java.lang.Object aTarget,
                                                                                 org.moe.natj.objc.SEL aSelector,
                                                                                 java.lang.Object anArgument)
      • classFallbacksForKeyedArchiver

        public static NSArray<java.lang.String> classFallbacksForKeyedArchiver()
      • classForKeyedUnarchiver

        public static org.moe.natj.objc.Class classForKeyedUnarchiver()
      • debugDescription_static

        public static java.lang.String debugDescription_static()
      • description_static

        public static java.lang.String description_static()
      • hash_static

        public static long hash_static()
      • instanceMethodSignatureForSelector

        public static NSMethodSignature instanceMethodSignatureForSelector​(org.moe.natj.objc.SEL aSelector)
      • instancesRespondToSelector

        public static boolean instancesRespondToSelector​(org.moe.natj.objc.SEL aSelector)
      • isSubclassOfClass

        public static boolean isSubclassOfClass​(org.moe.natj.objc.Class aClass)
      • keyPathsForValuesAffectingValueForKey

        public static NSSet<java.lang.String> keyPathsForValuesAffectingValueForKey​(java.lang.String key)
      • new_objc

        public static java.lang.Object new_objc()
      • resolveClassMethod

        public static boolean resolveClassMethod​(org.moe.natj.objc.SEL sel)
      • resolveInstanceMethod

        public static boolean resolveInstanceMethod​(org.moe.natj.objc.SEL sel)
      • setVersion_static

        public static void setVersion_static​(long aVersion)
      • superclass_static

        public static org.moe.natj.objc.Class superclass_static()
      • version_static

        public static long version_static()
      • addService

        public void addService​(CBMutableService service)
        addService: Publishes a service and its associated characteristic(s) to the local database. If the service contains included services, they must be published first.
        Parameters:
        service - A GATT service.
      • delegate

        public CBPeripheralManagerDelegate delegate()
        [@property] delegate The delegate object that will receive peripheral events.
      • initWithDelegateQueue

        public CBPeripheralManager initWithDelegateQueue​(CBPeripheralManagerDelegate delegate,
                                                         NSObject queue)
        initWithDelegate:queue: The initialization call. The events of the peripheral role will be dispatched on the provided queue. If nil, the main queue will be used.
        Parameters:
        delegate - The delegate that will receive peripheral role events.
        queue - The dispatch queue on which the events will be dispatched.
      • initWithDelegateQueueOptions

        public CBPeripheralManager initWithDelegateQueueOptions​(CBPeripheralManagerDelegate delegate,
                                                                NSObject queue,
                                                                NSDictionary<java.lang.String,​?> options)
        initWithDelegate:queue:options: The initialization call. The events of the peripheral role will be dispatched on the provided queue. If nil, the main queue will be used.
        Parameters:
        delegate - The delegate that will receive peripheral role events.
        queue - The dispatch queue on which the events will be dispatched.
        options - An optional dictionary specifying options for the manager.
        See Also:
        CBPeripheralManagerOptionShowPowerAlertKey, CBPeripheralManagerOptionRestoreIdentifierKey
      • isAdvertising

        public boolean isAdvertising()
        [@property] isAdvertising Whether or not the peripheral is currently advertising data.
      • removeAllServices

        public void removeAllServices()
        removeAllServices Removes all published services from the local database.
      • removeService

        public void removeService​(CBMutableService service)
        removeService: Removes a published service from the local database. If the service is included by other service(s), they must be removed first.
        Parameters:
        service - A GATT service.
      • respondToRequestWithResult

        public void respondToRequestWithResult​(CBATTRequest request,
                                               long result)
        respondToRequest:withResult: Used to respond to request(s) received via the @link peripheralManager:didReceiveReadRequest: @/link or [@link] peripheralManager:didReceiveWriteRequests: @/link delegate methods.
        Parameters:
        request - The original request that was received from the central.
        result - The result of attempting to fulfill request.
      • setDelegate_unsafe

        public void setDelegate_unsafe​(CBPeripheralManagerDelegate value)
        [@property] delegate The delegate object that will receive peripheral events.
      • setDelegate

        public void setDelegate​(CBPeripheralManagerDelegate value)
        [@property] delegate The delegate object that will receive peripheral events.
      • setDesiredConnectionLatencyForCentral

        public void setDesiredConnectionLatencyForCentral​(long latency,
                                                          CBCentral central)
        setDesiredConnectionLatency:forCentral: Sets the desired connection latency for an existing connection to central. Connection latency changes are not guaranteed, so the resultant latency may vary. If a desired latency is not set, the latency chosen by central at the time of connection establishment will be used. Typically, it is not necessary to change the latency.
        Parameters:
        latency - The desired connection latency.
        central - A connected central.
        See Also:
        CBPeripheralManagerConnectionLatency
      • startAdvertising

        public void startAdvertising​(NSDictionary<java.lang.String,​?> advertisementData)
        startAdvertising: Starts advertising. Supported advertising data types are CBAdvertisementDataLocalNameKey and CBAdvertisementDataServiceUUIDsKey. When in the foreground, an application can utilize up to 28 bytes of space in the initial advertisement data for any combination of the supported advertising data types. If this space is used up, there are an additional 10 bytes of space in the scan response that can be used only for the local name. Note that these sizes do not include the 2 bytes of header information that are required for each new data type. Any service UUIDs that do not fit in the allotted space will be added to a special "overflow" area, and can only be discovered by an iOS device that is explicitly scanning for them. While an application is in the background, the local name will not be used and all service UUIDs will be placed in the "overflow" area. However, applications that have not specified the "bluetooth-peripheral" background mode will not be able to advertise anything while in the background.
        Parameters:
        advertisementData - An optional dictionary containing the data to be advertised.
        See Also:
        CBAdvertisementData.h
      • stopAdvertising

        public void stopAdvertising()
        stopAdvertising Stops advertising.
      • updateValueForCharacteristicOnSubscribedCentrals

        public boolean updateValueForCharacteristicOnSubscribedCentrals​(NSData value,
                                                                        CBMutableCharacteristic characteristic,
                                                                        NSArray<? extends CBCentral> centrals)
        updateValue:forCharacteristic:onSubscribedCentrals: Sends an updated characteristic value to one or more centrals, via a notification or indication. If value exceeds maximumUpdateValueLength, it will be truncated to fit.
        Parameters:
        value - The value to be sent via a notification/indication.
        characteristic - The characteristic whose value has changed.
        centrals - A list of CBCentral objects to receive the update. Note that centrals which have not subscribed to characteristic will be ignored. If nil, all centrals that are subscribed to characteristic will be updated.
        Returns:
        YES if the update could be sent, or NO if the underlying transmit queue is full. If NO was returned, the delegate method @link peripheralManagerIsReadyToUpdateSubscribers: @/link will be called once space has become available, and the update should be re-sent if so desired.
        See Also:
        maximumUpdateValueLength
      • publishL2CAPChannelWithEncryption

        public void publishL2CAPChannelWithEncryption​(boolean encryptionRequired)
        publishL2CAPChannelWithEncryption: Create a listener for incoming L2CAP Channel connections. The system will determine an unused PSM at the time of publishing, which will be returned with @link peripheralManager:didPublishL2CAPChannel:error: @/link. L2CAP Channels are not discoverable by themselves, so it is the application's responsibility to handle PSM discovery on the client.
        Parameters:
        encryptionRequired - YES if the service requires the link to be encrypted before a stream can be established. NO if the service can be used over an unsecured link.
      • unpublishL2CAPChannel

        public void unpublishL2CAPChannel​(char PSM)
        unpublishL2CAPChannel: Removes a published service from the local system. No new connections for this PSM will be accepted, and any existing L2CAP channels using this PSM will be closed.
        Parameters:
        PSM - The service PSM to be removed from the system.
      • authorization_static

        public static long authorization_static()