Rectangle 27 3

Yes you can test your app on Device an Simulator simultaneously. I'm developing an app with Multipeer Connectivity right now and communication between Iphone and Simulator works fine. I'm running it on a MacBook Air. All you have to do is to make sure, that Bluetooth is enabled on your Mac. You can do this in System Preferences -> Bluetooth.

Thanks for your reply, unfortunately the mac mini makes the pair but keeps me disconnected. Makes a connection with the iphone but it lasts 1 sec then it disconnects and a notification says "network is unavailable - make sure network access is enabled". The connection is between an iphone4 and a new mac mini

ios - multipeer connectivity test on iphone and a simulator simultaneo...

ios objective-c cocoa-touch multipeer-connectivity
Rectangle 27 1

I suggest you to watch Nearby Networking with Multipeer Connectivity WWDC 2013 video on the Apple developers center. There is an example about this stuff and this is very well explained.

PS : Yes you break NDA (september 14) but now it's ok :)

i have seen the video but it doesnt explain what happens when the user accepts the invitation

ios - Accepting invitation multipeer connectivity - Stack Overflow

ios multipeer-connectivity
Rectangle 27 2

In addition to testing on WiFi, you can also test your app based on "Multipeer Connectivity framework" on simulator and any IOS device using Bluetooth, As long as simulator and devices are connected in same Personal area network.

For example, on Iphone you can turn on Personal Hotspot (in your phone General settings) to connect your phone with your mac in same personal area network via bluetooth or WiFi and then try testing your app sharing messages between simulator and Iphone using any personal network based on Bluetooth or WiFi.

ios - multipeer connectivity test on iphone and a simulator simultaneo...

ios objective-c cocoa-touch multipeer-connectivity
Rectangle 27 4

The Multipeer Connectivity Framework probably is probably based on a proprietary protocol as I have nowhere seen that it implements PAN. It's only similar to it. As you mention, the list of supported profiles contains PAN as well with the following note:

Depending on the Bluetooth accessory, you may experience slight variations in profile functionality. These variations are governed by the accessory manufacturer, not the iOS device.

So in theory PAN is supported as is, and you should be able to connect with an arbitrary device that supports this profile. I connected my Android phone to my iPhone with the Personal Hotspot on the iPhone and the Android could use the shared internet connection without any issues.

I found the Raspberry Pi Bluetooth iPhone Tethering tutorial that seems to describe exactly what you are trying to do. For future reference I copy the steps here:

sudo aptitude install bluetooth bluez-utils bluez-compat

Pair the devices, this is the tricky part

pi@raspberrypi ~ $ hcitool scan
Scanning ...
    18:34:51:55:B0:D8   Fanboy ][
pi@raspberrypi ~ $
pi@raspberrypi ~ $ grep KeyboardDisplay /usr/bin/bluez-simple-agent 
    capability = "KeyboardDisplay"
pi@raspberrypi ~ $ sudo perl -i -pe 's/KeyboardDisplay/DisplayYesNo/' /usr/bin/bluez-simple-agent
pi@raspberrypi ~ $ grep DisplayYesNo /usr/bin/bluez-simple-agent
    capability = "DisplayYesNo"
pi@raspberrypi ~ $ 
pi@raspberrypi ~ $ sudo bluez-simple-agent hci0 18:34:51:55:B0:D8
RequestConfirmation (/org/bluez/18868/hci0/dev_18_34_51_55_B0_D8, 160178)
Confirm passkey (yes/no): yes
Release
New device (/org/bluez/18868/hci0/dev_18_34_51_55_B0_D8)
pi@raspberrypi ~ $
pi@raspberrypi ~ $ sudo bluez-test-device trusted 18:34:51:55:B0:D8 yes

Turn on the Personal Hotspot

pi@raspberrypi ~ $ echo "echo 'iface bnep0 inet dhcp' >> /etc/network/interfaces" | sudo sh
pi@raspberrypi ~ 

$ sudo pand -c 18:34:51:55:B0:D8 -role PANU --persist 30
pi@raspberrypi ~ $ ifconfig bnep0
bnep0     Link encap:Ethernet  HWaddr e0:91:53:61:0f:74  
          inet addr:172.20.10.10  Bcast:172.20.10.15  Mask:255.255.255.240
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:14 errors:0 dropped:0 overruns:0 frame:0
      TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:4426 (4.3 KiB)  TX bytes:802 (802.0 B)

thank you very much. unfortunately, I cannot test this until the beginning of next week, but I will report back as soon as I did.

Note that on iOS (unlike Android), you need to enable mobile data in order to activate personal hotspot.

Well, I finally came down to testing this: It does indeed work (more or less), but the problem I am having is that I want to programmatically connect to a bluez PAN from an iOS device, and I still can't see how I can do that? In fact, usingt MCNearbyServiceBrowser does not seem to be noticed by the pi at all. Can I somehow sniff the BT packets sent by the iphone to maybe find out more about this?

You won't be able to do that. Only the user can modify any network settings.

The Multipeer Framework is a proprietary, closed source protocol. Additionally, it requires the MFi authenticator chip to make such a connection (hence only iOS devices are connectable.) So even if you could reverse engineer the protocol, you wouldn't be able to make any connections. On a non-Jailbroken iOS device the way I described is the only thing you can do, anything else with bluetooth requires MFi.

Multipeer Bluetooth Connection to non-iOS device - Stack Overflow

ios bluetooth bluetooth-lowenergy core-bluetooth multipeer-connectivity
Rectangle 27 2

Create a single class to manage all Multipeer Connections (like MCController.swift) and instantiate it as a singleton within your app delegate.This way, this single object (and the current connection state) can be accessed by all view controllers, much in the same way that UserDefauts is.

objective c - IOS: Multipeer Connectivity Framework - Stack Overflow

ios objective-c multipeer-connectivity
Rectangle 27 3

I reset the PeerID and Session on the Browser side whenever I get disconnected and want to reconnect:

// reset my PeerID.  Sometimes when trying to reconnect to the same Advertiser with the same PeerID nothing happens
    mcPeerID = [[MCPeerID alloc] initWithDisplayName:[UIDevice currentDevice].name];
    mcSession = [[MCSession alloc] initWithPeer:mcPeerID];
    mcSession.delegate = self;

    mcNearbyServiceBrowser = [[MCNearbyServiceBrowser alloc] initWithPeer:mcPeerID serviceType:kMCServiceType];
    mcNearbyServiceBrowser.delegate = self;
    [mcNearbyServiceBrowser startBrowsingForPeers];

On the Advertiser side, the connectedPeers count is decremented correctly on the disconnect, so reconnecting as a * different * browser doesn't seem to have a negative impact (maybe this isn't proper coding, but it works). With a new PeerID I can reconnect without issue. I reset the Session at the same time to keep them in sync (ie, I don't want a Session laying about that was init'd from the old PeerID).

ios - How to correctly tear down multipeer connectivity session? - Sta...

ios objective-c multipeer-connectivity
Rectangle 27 3

Socket.IO is nice because it is fairly simple to implement but it has the downside of requiring a central server. If you wanted to avoid that, you could use the Multipeer Connectivity framework that was introduced in iOS 7.

It will let you create one-to-one communication channels between devices on either the same WiFi network or Bluetooth. Once the channel is created, you can send whole NSData objects (or create streams but it doesn't seem relevant to your use case).

sockets - Communication between iOS app installed on different devices...

ios sockets
Rectangle 27 3

Socket.IO is nice because it is fairly simple to implement but it has the downside of requiring a central server. If you wanted to avoid that, you could use the Multipeer Connectivity framework that was introduced in iOS 7.

It will let you create one-to-one communication channels between devices on either the same WiFi network or Bluetooth. Once the channel is created, you can send whole NSData objects (or create streams but it doesn't seem relevant to your use case).

sockets - Communication between iOS app installed on different devices...

ios sockets
Rectangle 27 3

invitePeer: toSession: withContext: timeOut:
MCNearbyServiceBrowser
self
[browser invitePeer:selectedPeerID toSession:self.mySession withContext:nil timeout:timeInterval ];

However, if you're trying to troubleshoot accepting invitations I'd skip the alert view for now and just accept right away in the didReceiveInvitation: callback of the advertiser delegate.

I'd originally stated that the delegate callbacks from Multipeer Connectivity classes came in on private queues but as @Juguang pointed out this is only the case for MCSessionDelegate callbacks.

From my observation, only SessionDelegate methods are called from non-main queue (e.g. com.apple.MCSession.SyncQueue) , NearbyServiceBrowser or Advertiser's are from main queue.

@Juguang yes you're right - I noticed this myself some time later. Forgot all about this question. Edited - thanks.

ios - Sending and Receiving an Invitation with Multipeer Connectivity ...

ios objective-c bluetooth p2p multipeer-connectivity
Rectangle 27 3

For anyone interested, I created MCSessionP2P, a demo app that illustrates the ad-hoc networking features of MCSession. SessionController conforms to MCSessionDelegate, MCNearbyServiceBrowserDelegate and MCNearbyServiceAdvertiserDelegate and acts as the datasource for a UITableView. The app advertises itself via Wi-Fi or Bluetooth and programmatically connects to available peers, establishing a peer-to-peer network.

@Macro : I had downloaded your code, it's working fine, but sometime is connecting and some not, can you tell me how ?

ios - Sending and Receiving an Invitation with Multipeer Connectivity ...

ios objective-c bluetooth p2p multipeer-connectivity
Rectangle 27 0

For anyone interested, I created MCSessionP2P, a demo app that illustrates the ad-hoc networking features of MCSession. SessionController conforms to MCSessionDelegate, MCNearbyServiceBrowserDelegate and MCNearbyServiceAdvertiserDelegate and acts as the datasource for a UITableView. The app advertises itself via Wi-Fi or Bluetooth and programmatically connects to available peers, establishing a peer-to-peer network.

@Macro : I had downloaded your code, it's working fine, but sometime is connecting and some not, can you tell me how ?

ios - Sending and Receiving an Invitation with Multipeer Connectivity ...

ios objective-c bluetooth p2p multipeer-connectivity
Rectangle 27 0

I suggest you to watch Nearby Networking with Multipeer Connectivity WWDC 2013 video on the Apple developers center. There is an example about this stuff and this is very well explained.

PS : Yes you break NDA (september 14) but now it's ok :)

i have seen the video but it doesnt explain what happens when the user accepts the invitation

ios - Accepting invitation multipeer connectivity - Stack Overflow

ios multipeer-connectivity
Rectangle 27 0

If you are targeting ios 7 and above Multipeer Connectivity Framework is the way to implement this. It provides u with a decent api to connect multiple apps on devices which become peers and then can share data with each other.

Multipeer Framework connects peers(apps installed on multiple devices in your case) on local Wifi Network or by using Bluetooth. If you want to share data over the internet between your apps installed on multiple devices in my opinion HTML5 WebSockets is the way to go.

ios - Connect iPhone app with iPad app - Stack Overflow

ios objective-c iphone ipad networking
Rectangle 27 0

session:didReceiveData is called by the Mulitipeer Connectivity Framework from a dedicated thread. You are trying to update a label from this dedicated thread. This is not allowed, you should only access UI elements from the main queue. The solution is to dispatch the piece of code that updates the label to the main queue.

You can do it in receivedTap:withLabelText as follows:

- (void)receivedTap:(NSString *)gesture withLabelText:(NSString *)labelText {
    NSLog(@"%@", gesture);
    NSLog(@"%@", labelText);
    dispatch_async(dispatch_get_main_queue(), ^{
        self.tapGestureLabel.text = labelText; 
    });
}

Or deal with it earlier in session:didReceiveData:fromPeer

dispatch_async(dispatch_get_main_queue(), ^{
    [_gestureViewController receivedTap:gesture withLabelText:tapString];
});

Awesome, how would I go about dispatching to the main queue / thread? @PeterFennema

I added what I thought was dispatching to the main thread above in the description. @PeterFennema

using [self performSelectorOnMainThread:@selector(changeImage:) withObject:image waitUntilDone:NO]; does the trick.

ios - How to change a views UILabels, UIButtons, UIViews, etc. from a ...

ios objective-c multipeer-connectivity
Rectangle 27 0

Well, based on responses from the Apple Dev Forums, the answer is NO. Multipeer Communications is not supported while operating in the background. For those with access, link here: Apple Dev Forum

I investigated this in Feb 2015, and it still seems that the answer is NO in iOS 8.1

ios - Can I have a multipeer connectivity session run in the backgroun...

ios multipeer-connectivity
Rectangle 27 0

Apple have confirmed that "Multipeer Connectivity does not function in the background". The reason is that if your app is suspended then its socket resources can be reclaimed and everything falls apart.

However, it is possible to monitor iBeacons when in the background. Essentially, you set your app up to monitor proximity to a beacon with a specific id. Then, your app that is in the foreground becomes a beacon with that same id. This causes the following app delegate method to be called on the app in the background:

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region {
    UILocalNotification *notification = [[UILocalNotification alloc] init];

    if(state == CLRegionStateInside) {
        notification.alertBody = NSLocalizedString(@"A nearby app would like to connect", @"");
    } else {
        return;
    }
    [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}

Here you issue a local notification that, when tapped on by the user, will bring your app into the foreground, at which point you can start advertising for a peer-to-peer connection.

This article leftshift.io/ says the following: the Multipeer Connectivity framework is thread safe and applications can create and maintain connections even when in the background... Isn't it possible to start advertising as soon as the delegate method you mentioned gets called?

The app is only launched momentarily when the region is entered and it is not possible to start advertising there. My experience is that any peer-to-peer connection is dropped within 5 seconds of the app being backgrounded and this has been confirmed by an Apple expert in this field. As you say in the the question, your experience is also that connections cannot be made in the background.

Yeah, that's what I was afraid of. But how does Firechat handle all this? One hour after I close the app on both devices, I can still send messages to the other device when I open the app on one of them. Probably they are sending the message via CoreBluetooth, because I can see the devices are connected via bluetooth when I open the settings app.

ios - Multipeer connectivity with one device having app running in bac...

ios multipeer-connectivity
Rectangle 27 0

You can use KVO on fractionCompleted something like that

[_progress addObserver:self 
        forKeyPath:@"fractionCompleted" 
           options:NSKeyValueObservingOptionNew 
           context:NULL];
- (void)observeValueForKeyPath:(NSString *)keyPath 
                          ofObject:(id)object 
                            change:(NSDictionary *)change 
                           context:(void *)context
    {
        if (object == _progress) {
            // Handle new fractionCompleted value
            return;
        }

    [super observeValueForKeyPath:keyPath 
                     ofObject:object 
                       change:change 
                      context:context];
}

ios - track changes in NSProgress with Multipeer Connectivity - Stack ...

ios multipeer-connectivity
Rectangle 27 0

It would be helpful to know what action triggers startSync: but in setUpPP you are assigning a meaningless instance of MCPeerID (with no displayName) to self.SSid so I could see that crash happening if startSync: is ever called before self.SSid gets a real MCPeerID assigned to it.

My suggestion would be to start out with self.SSid as nil, and make sure that you are not sending invitations unless that property has a value. Going further I wouldn't rely on a single property to store an MCPeerID that could have it's value changed before startSync: is called.

Thanks for the input. You are right that it is not ideal to allocate SSid before it gets a value. I will change that. However, it seems that the problem (at least partly) was that the device connected to itself. So checking that and making sure to tear down the session when losing connection seemed to have improved things. Really frustrating not being able to recreate the crash though, I had to guess, post an update and see what crash reports are coming in.

ios - Occasional crash when inviting peer in multipeer connectivity - ...

ios multipeer-connectivity
Rectangle 27 0

Instead of using an MCBroswerViewController, you can use MCNearbyServiceBrowser. It will then call a delegate method:

- (void)browser:(MCNearbyServiceBrowser *)browser foundPeer:(MCPeerID *)peerID withDiscoveryInfo:(NSDictionary *)info;

Then you can automatically send an invitation with something like:

[browser invitePeer:peerID
            toSession:self.session
          withContext:nil
              timeout:10];

However, in doing this, I've ran into tons of other problems. So far it seems:

  • If both devices send invitations and accept them, then they randomly disconnect very soon.

I'm actually working on an open source library right now to try and do exactly what you're asking for: Connect devices without any invitations or browser necessary (no UI).

However, it is not working yet. I haven't fully solved both issues above, but if you want to check out the code and see what you can work out, go for it. Please let me know of any progress you make though. This framework is frustrating to deal with...

I found out eventually about MCNearbyServiceBrowser and created an implementation. I know about the problems when both send invitations and accept them so what i did was to give one peer priority over the other. The priority is defined by who has the earliest "open app" timestamp (who opened the app first) and who has already peers connected. I store this information in the DiscoveryInfo NSDictionary. :) The peer with priority gets to send the invitation while the other just waits.

Another way of doing this is just comparing the peerIDs. Whoever has a lower peerID gets priority.

ios - Is it possible to connect to a Multipeer Connectivity session wi...

ios objective-c multipeer-connectivity
Rectangle 27 0

This isn't possible with the Multipeer Connectivity Framework, but what you could do is implement your own method of determining a device's signal strength as in this SO question, and then pass that signal strength value to peers in your MCNearbyServiceAdvertiser's discoveryInfo

ios - Multipeer - Peer Connection Strength detection - Stack Overflow

ios multipeer-connectivity