Connect Browser & Advertiser without showing alert message in Multipeer connectivity - ios

Currently i am exploring the multipeer connectivity framework.I have 2 option in my application Advertiser & Browser.
So when user fire up the browser on one device, and the advertiser on another then they should be able to find each other. When the device appears in the browser, and the user taps on it, then the user with the advertising device will be presented with an alert allowing them to choose whether or not to make the connection.
But i want when browser taps any particular advertiser it will automatically make connection without alert message.
Note:- Currently i am using MCBrowserViewController and MCAdvertiserAssistant
So is it possible to do ? Can any one have done it ?

The Multipeer Connectivity framework provides additional APIs that support programmatic discovery and customize the experience beyond what’s provided by MCBrowserViewController and MCAdvertiserAssitant.
This way you can immediately send out an invite without waiting for user interaction.
MCNearbyServiceBrowser and MCNearbyServiceAdvertiser provide methods to handle programmatic discovery for the browser and advertiser respectively. The MCNearbyServiceBrowserDelegate protocol supports your custom browser by enabling you to respond to finding nearby devices, while MCNearbyServiceAdvertiserDelegate helps you handle browser invitations programmatically.
You’ll have to do the heavy lifting in your code to construct your browser’s UI, present nearby devices and initiate invitations to peers. On the advertiser end, the UI work involves presenting the invitation to the user, getting the user’s response, and calling a handler to pass the user response to the browser.
However, once the peers are connected, sending data works exactly the same as
before.
To see how to set up these check out NSHipster for some additional code examples of this at this link. He uses an UIActionSheet but you could simply just accept the invitation in advertiser:didReceiveInvitationFromPeer:withContext:invitationHandler:.
invitationHandler(YES, self.session);

Related

When does iOS display "need to bond" dialog?

I am writing an iOS app that communicates with a BLE device that we are developing. Most communication does not require bonding, but there are some secure features where bonding will be required. I've put those secure features in a separate service which has been flagged as requiring bonding, and when I try to access that service iOS correctly starts the bonding process.
The problem I'm having, is that I want to be able to control exactly when this bonding takes place so I can design my UI appropriately. Most of the time, iOS waits until I try to access the secure service before it starts the bonding process, but I have also seen the bonding dialog appear shortly after I call CBPeripheral.DiscoverCharacteristics() and long before I actually use the secure service for anything. The bonding dialog seems to appear later if I'm re-running the app when I've already bonded once and then deleted the bonding both in iOS and the remote BLE device.
I'm guessing that iOS is caching the service/characteristic information, so after the first connection when I call CBPeripheral.DiscoverCharacteristics() it's not actually communicating with the remote BLE device, and thus isn't triggering the need to bond.
There's a discussion about how to clear the bluetooth cache on OSX, but nothing similar for iOS. I've tried this:
Unbond device in iOS
Turn off Bluetooth
Turn off iPad
Turn iPad back on
Turn Bluetooth back on
But the bonding request dialog still comes later, which I'm guessing means the cache didn't actually get cleared.
If the devices are unbonded and the peripheral sends an SMP "Security Request", it will show the popup.
It also shows it when you try to interact with a protected characteristic.

Monitoring network changes in iOS

I have an application that needs to monitor network changes.
Let's say if Wi-Fi was dropped or reconnected then I need to use some web services.
How can I accomplish this in iOS? I have a captive network that marks users as authenticated after logging in. I want to make sure that the user is authenticated whenever Wi-Fi changes, otherwise I need to perform authentication.
All I want is to perform some HTTP requests on the basis of network changes.
Any help is appreciated. I have tried to use Reachability but that only works when user opens the application.
Reachability allows the app to be notified when the network configuration change.
I used this method:
+ (instancetype)reachabilityForInternetConnection return [self connectivityWithAddress:&zeroAddress];
My apps recieve regular callbacks when I play with the wifi connection.

Handling multiple Bluetooth Pairing Request Dialogs at once

I have an app that integrates with BLE devices. I can connect to any number of devices. When initiating a pairing from the app to the device via [CBCentralManager connectPeripheral:options:] the system bluetooth pairing request alert will fire if no previous pairing information is found. This all works great.
However, I am implementing a functionality that discovers, pairs, and reads characteristics from multiple devices at once. This also works great if the devices have been paired previously. But if this is the first pairing for more than one of the devices, only one of the pairing request alert controllers is displayed. What makes this even more difficult is that I also don't receive a failed connection error from CB for the other devices waiting for response from the pairing dialog.
Is there any way I can elegantly handle situations where there are multiple pairing requests needing attention? It would be helpful if at least one of these was possible:
The ability to complete the outstanding pair requests sequentially
Notification of failed pairing for other devices
Knowledge of whether a pairing request dialog will be fired before initializing the pairing so I can pair one at a time
There are no APIs in CoreBluetooth that lets you interact with the pairing.
Are you in control of the firmware of the peripherals you want to be able to pair with? If so, you can enable notifications and send events how the pairing process is going. That way you know in the app the current status of a pairing process.
For some examples, by looking at status and error codes (details depends on your peripheral BLE stack), you will be able to identify when iOS shows the pair dialog, when the user presses cancel and when pairing succeeds. It will also be possible to identify when iOS didn't put up the pair dialog.

Don't show cellular data warning on iOS

If a user decides to not allow an app to access cellular data every time they try to open the app they are shown a warning telling them that cellular data is turned off.
Is there a way in the SDK to stop showing this message or control when / where it is displayed?
The system will show this message if you try to access the Internet when permission has been revoked. To prevent it from appearing, you could use Apple's Reachability code to detect network availability, and only make web calls if the network is available.
See also, this StackOverflow post.

Send data from an iOS app when connection is restored

I'm creating an app that allows the user to work without internet connection. When he wants to publish his progress to the web server it gets stored in the device's database. If he isn't connected to the internet I have to send it when he gets internet connection back.
How can I run the code to send the data to the database when internet connection is available again?
In Android I used a broadcast receiver to listen for a "connection changed" event to accomplish this but I don't seem to find a way in iOS to do the same.
You could try to check if the device has an active internet connection (3G and/or Wi-Fi for iPhone, Wi-Fi for iPad/iPod Touch), there are many ways to do that but the simplest in my opinion is to use Reachability.
Check this similar question for more informations about Reachability and how to implement it in your project. It can even be used in a if statement so you can make the user able to publish or not depending on his internet connection.

Resources