I just upgraded an app written in Swift 1.2 with xCode 6.4 to Swift 2 with xCode 7.0.1.
The upgraded app builds and runs fine, but multipeer can not establish a connection between a phone and simulator once invitations are issued. It was working fine before the upgrade, and I was forced to make a few changes to the multipeer code during the upgrade.
There were lots of methods that needed their signatures changed: (This is one of many methods that wanted the exclamation removed)
- func advertiser(advertiser: MCNearbyServiceAdvertiser!, didReceiveInvitationFromPeer peerID: MCPeerID!, withContext context: NSData!, invitationHandler: ((Bool, MCSession!) -> Void)!) {
+ func advertiser(advertiser: MCNearbyServiceAdvertiser, didReceiveInvitationFromPeer peerID: MCPeerID, withContext context: NSData?, invitationHandler: ((Bool, MCSession) -> Void)) {
Then, nil could no longer be passed when rejecting an invitation:
- invitationHandler(false, nil)
+ invitationHandler(false, self.session)
I've been reading about recent changes in encryption preferences. I've been using the minimal constructor without encryption declaration for the session:
self.session = MCSession(peer: peerId)
I've unsuccessfully tested an iphone 6 with iOS 9.0.2 and a simulator run by xCode 7.0.1 on both yosemite and el capitan connected to the same wifi network with bluetooth enabled and disabled. The browser that issued the invitation recieves a NotConnected and LostPeer quickly and the advertiser becomes aware as expected. This is similar behavior to what I saw before when the devices were not on the same network.
Is there anything I have overlooked in the upgrade? I can't find any similar issues in the forum or stackoverflow.
Any assistance is appreciated.