objective c - iOS Multipeer Connectivity didReceiveInvitationFromPeer did not -
objective c - iOS Multipeer Connectivity didReceiveInvitationFromPeer did not -
i know question has been asked many times, after reading each of them more few times, still can't multipeer connectivity
work. sending not receiving invitation. here code:
@implementation mpcmanager - (id)init { self = [super init]; if (self) { _mypeerid = nil; _session = nil; _browser = nil; _advertiser = nil; } homecoming self; } - (void)automaticbrowseandadvertisewithname:(nsstring *)displayname { _mypeerid = [[mcpeerid alloc] initwithdisplayname:displayname]; _session = [[mcsession alloc] initwithpeer:_mypeerid]; _session.delegate = self; _advertiser = [[mcnearbyserviceadvertiser alloc] initwithpeer:_mypeerid discoveryinfo:nil servicetype:@"trm-s"]; _advertiser.delegate = self; [_advertiser startadvertisingpeer]; _browser = [[mcnearbyservicebrowser alloc] initwithpeer:_mypeerid servicetype:@"trm-s"]; _browser.delegate = self; [_browser startbrowsingforpeers]; } - (void)session:(mcsession *)session didreceivecertificate:(nsarray *)certificate frompeer:(mcpeerid *)peerid certificatehandler:(void (^)(bool accept))certificatehandler { certificatehandler(yes); } - (void)advertiser:(mcnearbyserviceadvertiser *)advertiser didreceiveinvitationfrompeer:(mcpeerid *)peerid withcontext:(nsdata *)context invitationhandler:(void (^)(bool, mcsession *))invitationhandler { nslog(@"this not getting called"); } - (void)browser:(mcnearbyservicebrowser *)browser didnotstartbrowsingforpeers:(nserror *)error { nslog(@"%@", [error localizeddescription]); } - (void)browser:(mcnearbyservicebrowser *)browser foundpeer:(mcpeerid *)peerid withdiscoveryinfo:(nsdictionary *)info { nslog(@"this getting called"); } - (void)invitepeer:(mcpeerid *)peerid { nslog(@"this getting called"); [_browser invitepeer:peerid tosession:_session withcontext:nil timeout:30]; }
i running on 2 simulators, , working time, stopped suddenly. ideas on how or problem?
make sure serializing , reusing mcpeerid objects whenever possible. each time phone call - (instancetype)initwithdisplayname:(nsstring *)mydisplayname
returns unique instance.
what happens in dev environment end flood of advertisers , browsers , ton of ghost duplicates in bonjour advertising space. can cause go wonky.
if using simulators resetting them may help. on hardware can restart or toggle aeroplane mode.
take @ this year's wwdc session on multipeer named "cross platform nearby networking". has best practices follow help immensely.
ios objective-c
Comments
Post a Comment