3

This one's a bit weird so I'll try explaining as best as I can. I'm working on Baby's First iPad App (Swift) and I've gotten reasonably far after reading a couple good books, tutorials, etc.

There are two apps which need to communicate. One runs on my macbook (which I'll just call osx_app) and one which runs on an ipad. osx_app has a class which implements MCSessionDelegate and contains the advertiser (MCAdvertiserAssistant) and session objects as properties. When the user hits the "Start Hosting" menu item, the session delegate subclass starts the advertiser and waits for ipad_app to connect.

Meanwhile, ipad_app has a class which implements MCSessionDelegate and holds the session object as a property. The main view controller implements MCBrowserViewControllerDelegate and creates a browser using the MCSession held in the MCSessionDelegate implementer object.

The desired behavior is that ipad_app sees osx_app in the browser and connects. osx_app shows the dialog box and accepts. A connection is made, a log entry is printed, and an open file dialog opens to send a pdf to ipad_app.

Here's where the weird part comes in. I got that far. I got the connection running and the file sending and everything went really smoothly, but I wasn't implementing ipad_app, it was a pared down test app that I was using to learn the MC framework. I tested it a couple times on the iphone simulator and again on my iphone 5s and it worked perfectly.

Then when I ported the code over to the existing ipad_app code, it didn't work. At each connection state I do a simple print statement to see what's going on and as far as I can tell, ipad_app attempts the connection and osx_app spins its wheels for a minute and then disconnects. Both consoles log the "device connecting" and "device not connected" events.

Sometimes ipad_app will say it has connected to osx_app but the log for osx_app still just says "connecting." The weirdest part is that now the pared down MWE code I had, the one that worked perfectly, no longer works! I didn't do anything to the osx_app! Was it just a fluke that it worked the first couple of times?

Anywho, I've searched up and down for questions and answers about this and have only found a few people who report a similar problem but they either didn't solve it or their solution didn't work. I've tried using a real device, switching simulators, mutually excluding wifi and bluetooth to see if one or the other works better, disabling encryption, and disabling firewall.

I feel like maybe I'm just so unfamiliar with OSX and iOS programming that I passed an object in a way I wasn't supposed to or something? I don't even know.

Chris Gorman
  • 195
  • 1
  • 3
  • 8
  • I was looking a bit more and found an app that did something similar to what I want to do, https://github.com/jpsim/DeckRocket, but this person uses one project for their iOS and OSX apps. I noticed that every tutorial I've found uses MCF to communicate with other instances of the same app. I can't find it in the documentation, but maybe it can't be used to communicate with two different apps? I'll give it a shot and report back! – Chris Gorman Dec 21 '15 at 19:31

1 Answers1

3

Oh my god I figured it out. In ipad_app I had the MCSessionDelegate method session:didReceiveCertificate:fromPeer:certificateHandler implemented as a stub. I first re-wrote the MCF stuff so that I was using a custom advertiser and browser instead of the assistant and UI but that didn't work, so I searched for stuff about that and found this

Multipeer Connectivity: getting an invitation accepted (using built-in browser VC)

I deleted the stub from ipad_app and it worked!

Community
  • 1
  • 1
Chris Gorman
  • 195
  • 1
  • 3
  • 8