8

On Android I'm doing this way to create a service broadcast with a simple attacched map as info

HashMap<String, String> record = new HashMap<>();
record.put("info, "my android info");    
WifiP2pDnsSdServiceInfo serviceInfo = WifiP2pDnsSdServiceInfo
        .newInstance("_myservice", "_tcp", record);
WifiP2pManager manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
Channel channel = manager.initialize(this, this.getMainLooper(), null);
manager.addLocalService(channel, serviceInfo, null);

to retrieve another signal

manager.setDnsSdResponseListeners(channel, this, this);

@Override
public void onDnsSdTxtRecordAvailable(String fullDomainName, Map<String, String> txtRecordMap, WifiP2pDevice srcDevice)

On iOS it's the same service name and map of info

MCPeerID* _myPeerId=[[MCPeerID alloc] initWithDisplayName:@"my ios peer"];
NSDictionary* _serviceInfo=@{@"info": @"my ios info"};

MCNearbyServiceAdvertiser* _serviceAdvertiser = [[MCNearbyServiceAdvertiser alloc] 
         initWithPeer:_myPeerId discoveryInfo:_serviceInfo serviceType:@"myservice"];
_serviceAdvertiser.delegate=advertiseDelegate;

MCNearbyServiceBrowser* _serviceBrowser=[[MCNearbyServiceBrowser alloc] 
      initWithPeer:_myPeerId serviceType:@"myservice"];
_serviceBrowser.delegate=browserDelegate;

[_serviceAdvertiser startAdvertisingPeer];
[_serviceBrowser startBrowsingForPeers];

and the delegates

-(void)browser:(MCNearbyServiceBrowser *)browser lostPeer:(MCPeerID *)peerID
-(void)browser:(MCNearbyServiceBrowser *)browser foundPeer:(MCPeerID *)peerID withDiscoveryInfo:(NSDictionary<NSString *,NSString *> *)info

An Android device can see only another Android device, likewise between iOS devices. However, the two families can't see each other. I'd like to have them seen by other devices regardless of the operating system.

user3290180
  • 4,260
  • 9
  • 42
  • 77

0 Answers0