If I want to have my iOS device act as a "server" and broadcast its bluetooth services to other iOS devices, how would I use the core-bluetooth framework (or any other iOS framework) to implement this? So far, all I've seen from the corebluetooth framework is how to write the client-side of things. (Scanning, connecting to existing bluetooth services)
You can make use of the OSX sample project called DNSSDObjects. The core classes (three of them) work just fine under iOS. The code requires a few small changes to work with Bluetooth (as-is they only work with WiFi). See my answer to another question for the required code changes.
Basically you use whatever code you need to setup your server and begin accepting socket connections. You then use the DNSSDRegistration class to advertise your server via Bonjour.
The other two classes, DNSSDBrowser and DNSSDService can be used by iOS client code to find the server, or any app or program that can find Bonjour services will also be able to find your server.
There are two great WWDC video that show how to act as either the client or the server using an appropriate iOS device. They can be found here, you're looking for sessions 703 and 705.
Downloads of the source that they use can be found here. You'll need a developer account (free works) to login and view/download.
Related
I'm trying to write a super-simple iOS app, just for personal use (i.e. it doesn't need to conform to any App Store stuff). I want it to do the following. Assume it's installed on two devices, both of which I own/control.
On device 1, it has a button that, when pressed, will immediately cause a notification to pop up on device 2.
I'm fine with hardcoding specific apple IDs, device IDs, whatever; it's also fine if this only works when the two devices are on the same LAN/Wifi. all I want is for the above to work, in the easiest way possible, and preferably without needing anything to run on a server anywhere.
How simply can this be implemented? I've set up a whole push-notification system once before, but that required some server-side stuff. Hoping to be able to do this without any of that.
====
Update: realized I wasn't clear in the original post that I need the notification on Device 2 to pop up whether or not the app is currently open/running on that device.
I think that what you are searching for is multipeer connectivity framework.
The Multipeer Connectivity framework supports the discovery of
services provided by nearby devices and supports communicating with
those services through message-based data, streaming data, and
resources (such as files). In iOS, the framework uses infrastructure
Wi-Fi networks, peer-to-peer Wi-Fi, and Bluetooth personal area
networks for the underlying transport. In macOS and tvOS, it uses
infrastructure Wi-Fi, peer-to-peer Wi-Fi, and Ethernet.
source: https://developer.apple.com/documentation/multipeerconnectivity.
You can also check those tutorials:
https://www.ralfebert.com/ios-app-development/multipeer-connectivity/
https://www.hackingwithswift.com/example-code/networking/how-to-create-a-peer-to-peer-network-using-the-multipeer-connectivity-framework
Send sms to port is a way (the protocol will become SMS): https://developer.apple.com/documentation/foundation/nsportmessage
and Maybe Firebase Remote Config can help you: you can get your data in FCM remote config (key-value) from the app :
https://www.raywenderlich.com/17323848-firebase-remote-config-tutorial-for-ios
https://firebase.google.com/docs/remote-config/get-started?platform=ios
, and you can modify your data whenever you want, and the app can fetch it.
I have similar requirements, and it seems like APNS (Apple Push Notification Service) is required for this because it's one of the only ways to 'activate' an application that is in the background.
As a result, then the question is how to make APNS as painless as possible? It seems like combining Firebase Cloud Messaging (or FCM) (to manage APNS / sending messages), and Firebase Functions (to help manage FCM server-side requirements) is one decent option.
I want to transfer data from one app to another app from different iOS devices which have same WiFi network
I used MultipeerConnectivity framework and it works great
You need to implement Client/Server model for this in which if you want to transfer file from 1 device you need to make it server and make it discoverable on the go thourgh LAN/WIFI scanner libraries and then implement FTP/SMB protocols to transfer files. On the other side make the second device Client which will then discover devices on the same network and allow them to connect through the implemented protocols.
What task do you want to solve? Maybe MultipeerConnectivity framework will be appropriate in your case. It doesn't need event same wifi network
I have just delivered a prototype for a big client, everything was fine but I'm now curious to know if the solution/architecture I've chosen was the right one or there's place for improvement in case the project will keep on.
The task was to build two iOS apps: one running on 5 different iPhones, and another running on 2 iPads. Basically the iPhone applications had to communicate information to the iPads, and occasionally they also had to send information between each other (iPhone to iPhone). All the infos where small JSON objects/chunks whose size was small, really small.
The app was not intended to reach the app store, is a working prototype to test out some ideas in a user testing environment.
I discarded bluetooth because we are talking about a peer-to-peer communication, not a one-to-one.
What I did was to use web sockets thanks to SocketIO, through a small Node.js server that was running on my mac. The server was really simple, just receiving the messages from the clients and broadcasting information to the other ones.
What do you think? Is the solution I've chosen ok, or there are better ones?
For example, this morning I've just found out these thread here on SO, and I've discovered I could have used GameKit. What do you think?
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).
A good read : http://nshipster.com/multipeer-connectivity/
The WiTap sample from Apple demonstrates peer-to-peer networking over Wi-Fi and Bluetooth. Using Bonjour, the application both advertises itself on the local network and displays a list of other instances on the network. Supports infrastructure networks, peer-to-peer Bluetooth, and peer-to-peer Wi-Fi (on compatible hardware).
I have personally tested it and it works fine and well documented.
I think socket.io is the best choice. It is built on top of engine.io (which in turn is built on the fastest websocket implementation: ws) It has oldest to newest fallbacks, so it starts with long polling and works its way up. This guarantees a quick initial connection instead of needing to poll the device for features. You can read more on this here. Best of all, it handles everything seamlessly. You write your code as if websockets are supported on connecting devices and if not it will use other methods behind the scenes.
This post details many of the websocket libraries you could use with your server. Which websocket library to use with Node.js?
I am convinced Bonjour is the best solution:
Apps can also leverage Bonjour to automatically detect other instances
of the app (or other services) on the network.
However I've never used it myself; perhaps someone who has can comment?
I am trying to figure out how to connect to a cellular network and what classes of iOS I should use?
And, does iOS 7 support apps checking data in the background? It would be similar to checking if you were in a certain location.
Thanks!
Your phone will connect to a cellular network when you make any networking (internet) calls in your code. It will also connect to the internet through wifi, it doesn't care what type of connection you have, what you are trying to do is get info from the internet.
To do this, you must use some sort of networking library. The standard Apple-supported library is called NSURLSession and came out (an improvement upon the older NSURLConnection) with iOS7 and it works great. Suffer through the reading and you'll be rewarded - Link to Apple Docs
There's also a 3rd party library called AFNetworking created by Mattt (yes, 3 t's) that's awesome and probably the most used 3rd party iOS library there is. Highly, highly recommend looking into this and giving some consideration when wanting to talk to the internet through an app. - Link to AFNetworking
I'd like to use a computer using Windows 7 to provide data to an iOS device. I guess there is no way to do that by Wifi so I'd like to simulate a bluetooth GPS device on my Windows 7 computer so that the iOS device would connect to it.
My question is, what kind of data should I sent ? Can I directly send NMEA frames or should I implement another Apple protocol ? Where can I find specification on those protocol in iOS ?
The idea is to make geolocation data to be available to the whole system. Maybe by "simulating" a bluetooth external GPS receiver using a software that I would develop on Windows. So what kind of data should my Windows software send by bluetooth to iOS ? And how can it be detected by iOS as an external GPS receiver ?
Thanks.
I recommend to use bonjour.
It's a auto-connecting protocol which finds other "player" in the same subnet (lets say same "WiFi".
Theres a windows sdk written in C:
https://developer.apple.com/opensource/
How you do submit the data is up to you. You might create a JSON payload out of your GPS Data. You can also create a binary format and compress it with libz (zip) before sending it to your iOS Device through bonjour.
You can also set up a web server and a web service on your PC and simple connect to it through local network (WiFi) from your device. I think this requires the least work from both server and client side. Which format do you use (JSON, fractions of NMEA, something else) is really up to you since you will have to code both server and client side. For JSON and XML however there are a lot of free frameworks and even some SDK support on both client (iOS) and server (php, asp, servlets, etc) side.