A quick verification of Near by Interaction, a new feature in iOS 14.
Framework added from iOS14 SDK.
Locate and interact with nearby devices using identifiers, distance, and direction.
This makes it possible to identify and interact with nearby devices using identifiers / distances / directions.
You can't just use iOS14 (which should be released in the fall of 2020), and there is a limitation that you can only use it with an iPhone equipped with a U1 chip. As of September 2020, it can be used only on iPhone 11 series terminals (11, 11 Pro, 11 Pro Max).
If you agree to share your location / identifier with nearby devices, you can interact.
Ultra Wide Band (UWB) = A chip that can use wireless communication called ultra-wideband. This communication technology was originally used for industrial and military purposes, but it seems to be the first time to get on a consumer product. It seems that the release version at the moment is used only for speeding up AirDrop, but is it used for cooperation with forgotten items prevention tags and car key applications?
-[Unknown value of the original wireless chip "U1": Apple's future (6) \ | WIRED \ .jp](https://wired.jp/2020/06/21/u1-chip-future- of-apple-6 /) -ASCII \ .jp: Apple iPhone This year's hottest is "U1 chip" \ (1/4 )
--Multi-user AR, placing water balloons in each participant's hand --Identify the relative position of the driver and passengers in real time with a ride sharing app, etc. --Hockey-like game (figure below)
Image source: https://developer.apple.com/documentation/nearbyinteraction
Use servers, Bluetooth, P2P communication (Multipeer Connectivity), etc. to interact with nearby devices.
Each device creates a NISession
and uses the above network to exchange discovery tokens (NIDiscoveryToken
). When the token is received from the other party, the app actually starts a Near by Interaction (NI) session. The device's U1 chip manages the exchange of data, allowing NI to continuously provide relative positions to other devices.
let niSession = NISession()
When instantiating a session, the user is (apparently) prompted for permission.
Once you have the discovery token you are communicating with, you can start a session.
let token: NIDiscoveryToken = ...
let config = NINearbyPeerConfiguration(peerToken: token)
niSession.run(config)
When a session is executed, the token of the other party set by NI is verified, and if it is valid, session (_: didUpdate :)
of NISessionDelegate
can be called to obtain information on the relative position with the communication partner.
class ViewController: UIViewController {
func ...() {
niSession.delegate = self
}
}
extension ViewController: NISessionDelegate {
func session(_ session: NISession, didUpdate nearbyObjects: [NINearbyObject]) {
//NINearbyObject contains information about the communication partner
}
}
The delegate method will also be notified when the session is interrupted or disabled due to the background movement of the app. Used for restarting and error handling.
public protocol NISessionDelegate : NSObjectProtocol {
optional func session(_ session: NISession, didRemove nearbyObjects: [NINearbyObject], reason: NINearbyObject.RemovalReason)
optional func sessionWasSuspended(_ session: NISession)
optional func sessionSuspensionEnded(_ session: NISession)
optional func session(_ session: NISession, didInvalidateWith error: Error)
}
NINearbyObject
Take a look inside with Xcode.
@available(iOS 14.0, *)
open class NINearbyObject : NSObject, NSCopying, NSSecureCoding {
@NSCopying open var discoveryToken: NIDiscoveryToken { get }
}
@available(iOS 14.0, *)
@available(macOS, unavailable)
extension NINearbyObject {
public var distance: Float? { get }
public var direction: simd_float3? { get }
}
Quite minimal content. You can get the following 3 data.
The simd_float3
type used for direction data is like a three-dimensional vector. It seems that it is often used in ARKit and SceneKit.
Is it because the discovery token can be obtained because it is necessary to identify the other party when communicating with multiple other parties?
According to the official documentation, the following restrictions are required to provide accurate behavior:
--The distance between terminals is within 9 meters --Hold the terminal in portrait orientation --Terminals are back to back --There are no obstacles such as people, vehicles, or walls between the terminals.
It is said that the other terminal will be verified with the image shown below.
Image Source: https://developer.apple.com/documentation/nearbyinteraction/initiating_and_maintaining_a_session
I started two simulators and exchanged discovery tokens with each other via P2P communication to acquire relative location information data.
Although the distance of NINearbyObject
could be obtained without any problem, the direction always returns nil. Regarding this, it may be useless if you do not move it on the actual machine.
--There are some restrictions such as being limited to a fairly short distance, but it seems that you can accurately obtain the mutual position with a nearby terminal. --Currently, it can only be used on high-spec terminals ――Since it is "only" that you can get the data of the other party's location information, it seems that you have to use another channel (method) to take some action from here. In terms of API, that may be all right.
I think it would be interesting to use it for a meetup event or a meeting for a dating app. On the other hand, there are a lot of restrictions, so I get the impression that it has not yet reached the practical stage. I'm curious about what use cases will come out (or will they not be used at all?).