IOS Ability to connect multiple peer-to-peer networks while displaying the device name

I use iOS 7 multi-user technology to connect my iPad and iPod touch. But whenever iPod touch or iPad goes into sleep mode, it turns off, and this is normal, because multi-user mode does not work in the background, but when I open it again, it shows the iPod name twice in the list MCBrowserViewController. Tried this with every code sample, and every code has the same problem. Does anyone know how to fix this error.

There is also one strange problem with MCBrowserViewControllerif I connect the device and the other device accepts it even if it connects. MCBrowserViewControllerwill be displayed as a connection, and the button is "Done"disabled. I use MCBrowserViewControllerand there is no special code for it, so I think this is a problem from apple.

Also, does anyone know how to connect directly to the device when the application returns to active state from sleep mode?

+4
source share
2 answers

- , peerID (withDisplayName) , . , . , peerID - (, NSUserDefaults), , , peerID, , / .

: :

_peerID = [[MCPeerID alloc] initWithDisplayName:XXX];

:

//If there is no PeerID save, create one and save it
if ([[NSUserDefaults standardUserDefaults] dataForKey:@"PeerID"] == nil)
{
    _peerID = [[MCPeerID alloc] initWithDisplayName:XXX];
    [[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:_peerID] forKey:@"PeerID"];
}
//Else, load it
else
{
    _peerID            = [NSKeyedUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] dataForKey:@"PeerID"]];
}

, , , ..

+1

, , UIViewController , , , , -viewDidLoad, , viewDidLoad MCPeerID MCSession, , , , , MCPeerID MCSession AppDelegate .

0

Source: https://habr.com/ru/post/1537623/


All Articles