NEW: Subscribe to Hacking with Swift+ and accelerate your learning! >>

Day 83 - Project 25 MultipeerConnectivity

Forums > 100 Days of Swift

Hey guys, I'm just finished project 25, the MultipeerConnectivity thing. I want to let you know, that the project isn't working for me out of the box. I have to change the var mcAdvertiserAssistant: MCAdvertiserAssistant! to MCNearbyServiceAdvertiser! and to add the MCNearbyServiceAdvertiserDelegate protocoll. The rest is working fine.

Just want to let you know if you hit the same problem.

Stay sound and safe. zoran

   

I'm having trouble with this project as well, however, my issue is that the multipeer connection times out. I start by running it on the simulator and host the session. When I run it on my connected iOS device and join session, I can see the simulator and when I try connecting, I never get prompted on the simulator to accept/decline. This must be a security/entitlement setting but I cannot figure out what needs to be added.

Anyone know how to resolve this?

   

Has anyone managed to solve this problem? I tried @fxdlsRider's solution, but it didn't work, all connection attempts result in failure.

   

OK, with a few small changes in my Xcode project, I managed to make it work. The best news is, with this solution all the code presented by Paul is completely valid, so we don't need to change a single line in ViewController.swift. What we want to do is to OPT OUT of UISceneDelegate. Now I am still a beginner, so I am not aware of the long-run consequences of it, I just know that the project is working fine with the changes being done. Having this aside, let me write this down in a few steps:

  1. Go to Info.plist in your project and delete Application Scene Manifest row.
  2. Go to AppDelegate.swift and add var window: UIWindow? in the class.
  3. In the same class, delete everything below // MARK: UISceneSession Lifecycle line.

Now your simulator and the device should have no problem connecting to each other, no matter which one is the host.

I understand that by this method we lose the support of using scenes in our app, but in this particular case it shouldn't be a problem... hopefully :D

Also, I'd love to hear a comment on this by someone more experienced, so that we all learn if that solution is safe for our app.

See you tomorrow guys :D

3      

Hi all,

I have the same problem - I cannot connect with the device. I think that @MateusZ 's fix this with his approach but maybe someone found some other way to fix this? Thanks in advance for help!

   

@rgoff  

The solution given by @MateusZ worked for me.

The UISceneDelegate code is something new that the latest version of Xcode added to it's starting projects.

   

Hacking with Swift is sponsored by NSSpain

SPONSORED Announcing NSSpain 2020: Remote Edition! An online, continuous conference for iOS developers. We’ll start on Thursday and finish on Friday, with talks, activities, and lots of fun for 36 hours, non-stop. Sound good? Join us!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

Not logged in

Log in
 

Link copied to your pasteboard.