Search code examples
xcodeios7bluetoothcore-bluetoothmultipeer-connectivity

MultipeerConnectivityFramework in iOS 7


I am an iOS Developer working an application in which I want to list the bluetooth devices names (iPod, iPad, Macbook etc ), for which O am using the MultiPeerConnectivity Framework.

MultiPeerConnectivity Framework uses MCBrowserViewController which is responsible for browsing nearby devices and MCAdvertiserAssistant which advertise the devices for the connectivity. Using MultiPeerConnectivity Framework you have two devices, one should advertise itself and the second one should browse for the devices, than its working fine.

But My Problem is:
How to search for the devices which are not able to use the app (I mean how to search for my Macbook or other bluetooth devices like bluetooth keyboard etc, am not talking about the Android devices). Is it possible through MultiPeerConnectivity Framework ? or any other solution ?

Here is my code

-(void)setupPeerAndSessionWithDisplayName:(NSString *)_displayName
{
    self.peerID = [[MCPeerID alloc] initWithDisplayName:_displayName];
    self.session = [[MCSession alloc] initWithPeer:self.peerID];
    self.session.delegate = self;
}



-(void)setupMCBrowser{

    self.browser = [[MCBrowserViewController alloc] initWithServiceType:@"chat-files" session:self.session];
}



-(void)advertiseSelf:(BOOL)shouldAdvertise{

    if (shouldAdvertise) {
        self.advertiser = [[MCAdvertiserAssistant alloc] initWithServiceType:@"chat-files" discoveryInfo:nil session:self.session];

        [self.advertiser start];
    }
    else{
        [self.advertiser stop];
        self.advertiser = nil;
    }
}

Solution

  • If you are looking to discover other iOS devices, as well as other Macs and also peripherals, then you'll need to combine using Multipeer Connectivity with Core Bluetooth.

    MPC is intended for use in discovering other instances of your app. If you want to discover Macs then they will have to be running a Mac app with Multipeer Connectivity advertising with the same serviceType as your app.

    If you want to discover peripherals you will need to use Core Bluetooth - there are lots of tutorials available online, and you can also check this SO question as a starting point.