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.