ios – How you can examine if consumer has granted Multipeer Connectivity to hook up with different units?

I am beginning to use iOS’ Multipeer Connectivity and have the next:

class Connector : NSObject, ObservableObject
    @Printed var friends = [MCPeerID]()
    @Printed var occasion: String?

    personal let serviceType = "app"
    personal let peerId = MCPeerID(displayName: UIDevice.present.title)
    personal let serviceAdvertiser: MCNearbyServiceAdvertiser
    personal let serviceBrowser: MCNearbyServiceBrowser
    personal let session: MCSession

    personal let log = Logger()

    override init()
        session = MCSession(peer: peerId, securityIdentity: nil, encryptionPreference: .none)
        serviceAdvertiser = MCNearbyServiceAdvertiser(peer: peerId,
                                                      discoveryInfo: ["event" : "hello"],
                                                      serviceType: serviceType)
        serviceBrowser = MCNearbyServiceBrowser(peer: peerId, serviceType: serviceType)


        session.delegate = self
        serviceAdvertiser.delegate = self
        serviceBrowser.delegate = self



extension Connector : MCNearbyServiceAdvertiserDelegate
    func advertiser(_ advertiser: MCNearbyServiceAdvertiser, didNotStartAdvertisingPeer error: Error)
        log.error("ServiceAdvertiser didNotStartAdvertisingPeer: (String(describing: error))")

    func advertiser(_ advertiser: MCNearbyServiceAdvertiser,
                    didReceiveInvitationFromPeer peerID: MCPeerID,
                    withContext context: Information?,
                    invitationHandler: @escaping (Bool, MCSession?) -> Void)
    {"didReceiveInvitationFromPeer (peerID)")

... <fundamental different delegate stuff> ...

After I first create a Connector object, iOS pops up a typical alert asking if the consumer permits discovering and connecting to different units (along with the obligatory .plist privateness textual content I’ve set).

After I faucet “Do not Permit”, the advertiser(_:didNotStartAdvertisingPeer:) delegate methodology shouldn’t be referred to as. I additionally do not see something within the iOS APIs by which I can see (later, e.g. when app restarts) if the consumer has granted this or not.

Is there a means to determine what the consumer had chosen, like that is attainable with digital camera entry, location entry, …?

Related Articles


Please enter your comment!
Please enter your name here

Latest Articles