iOS/Swift: Quick & dirty way to send a notification to another device? - ios

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.

Related

If my iOS app pairs with a device using Core Bluetooth, will other apps have access to the device?

From Android documentation:
Caution: When a user pairs their device with another device using BLE, the data that's communicated between the two devices is accessible to all apps on the user's device.
For this reason, if your app captures sensitive data, you should implement app-layer security to protect the privacy of that data.
Is this also true for iOS? I haven't found anything on it and I assumed because iOS doesn't show the true MAC addresses of devices this wouldn't be an issue, but just wanted to check. Thanks
Yes, iOS also works in a similar way. And if you want private communication, you also need to maintain app layer security. Thus android wear, galaxy watch, and other similar devices use encrypted communication in the app layer.
If you already know the details. BLE communication works via Gatt Characteristics.
Consider there are two health applications running on an iOS device and the user also using an activity tracker device. In that case if the user wants to connect both of the health apps with that tracker, he certainly can do it. Both apps will be able to communicate with the activity tracker and get sensor data using the CBCentral module. Look at the diagram for Details.
On the other hand, In general, vice versa will not possible. Because if both iOS apps use Peripheral Role they will register two different instances of BLE-Service even if using the same UUID. Thus it will force two apps to communicate with completely different characteristics instances. However, it is also possible to work with two peripheral apps with the same UUID but this is not what the BLE developers ever wanted.
you need to provide app level security based on Service UUID, so that devices having the app with only same service UUID can connect.

Using Firebase Notifications cross platform

I'm searching for a solution for push notifications. For me Firebase is really attractive.
My question now is can I use it cross platform?
I think Firebase is a google service and thus will require the Google PlayServices, right? How can I consume Firebase Cloud Messages / Notificataion in my iOS App or Windows Store app.
I have a own backend where all the auth stuff and data is, but because I want to save time I don't want to implement a own solution
Is this possible or not? Or can you recommend me any other framework/service?
Yes, it's possible. FCM routes all of your iOS notifications to APNs, so by the time these notifications reach your iOS device, they look just like any other iOS notification.
If you want all the nitty-gritty details, this video might help.
In addition to Todd's answer
I think Firebase is a google service and thus will require the Google PlayServices, right?
Yup. For Android devices.
How can I consume Firebase Cloud Messages / Notificataion in my iOS App or Windows Store app.
Like Todd said, FCM forwards the messages for iOS devices to APNs. There is currently no Windows Phones client for FCM.
I have a own backend where all the auth stuff and data is, but because I want to save time I don't want to implement a own solution
To use FCM effectively accross different platforms, specially between Android and iOS, it is important to note that the behavior of message types are different to both.
Update: A recent feature was added for FCM that gives an option to provide specific params for supported specific platforms, called Platform Overrides.

Is Inter Process Communication possible between iOS applications using Sockets?

I have gone through a lot of articles on internet and most say that IOS applications allow IPC using protocol handlers (URL Schemes). But, Can't we achieve IPC using sockets, if one application opens a port and the other tries to connect to it ?
iOS8 introduced IPC support by exposing mach ports for so called "application groups". Check out this great tutorial:
http://ddeville.me/2015/02/interprocess-communication-on-ios-with-mach-messages/
It requires a bit of setup (to define application groups in dev portal, generate proper entitlements, etc..) but is not really so difficult and Xcode 6 does most of the job automatically (just enable "App groups" in general capacities section).
I can confirm, it works (I was able to create 2 apps sending messages to each other).
On iO7 there is no official support for IPS, but If you do not plan to upload your app to AppStore, you could try to exploit inter-app audio communication to achieve this.
Check out Apple's code sample, which demonstrated inter-app sound data stream between 3 apps:
https://developer.apple.com/library/ios/samplecode/InterAppAudioSuite/Introduction/Intro.html
Associated WWDS video:
https://developer.apple.com/wwdc/videos/#602
I haven't try to exploit it for non-audio usage but can't see the reason why shouldn't it work. Data rate is great, and sound data are just bytes and do not have to be redirected to the speaker, but interpreted however you like.
Of course, it will be rejected in AppStore review, but it is still fine for enterprise or own usage.
No, it is not for several reasons. 1) Apple does not allow this internally and has security layers to prevent this. 2) Applications fire applicationDiD/WillEnterBackground after a short delay, at which point the way you can interact with it plummets.
If you really want to send data between applications, set up a server with certs to match your app so you can use APN (apple push notifications) to send data in silent pushes to applications. Then, set up endpoints on the server that trigger those sends, and have apps consume the API that the server exposes.

Communication between iOS app installed on different devices on the same LAN

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?

How to broadcast bluetooth service in ios using corebluetooth?

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.

Resources