The need is to control the cameras, and LIDAR, on up to four iPhone 14 Pros from at Mac Studio they are connected to. The data from the iPhones is to be uploaded from the iPhone 14s to the MacStudio for processing. What I need help with is:
How can the iPhone 14s connected to MacStudio be enumerated on the Mac Studio to know how many there, are and their communication handles?
How can the camera application that takes the photos, and the other that takes LIDAR data, be communicated with over the Lighting Cables to send commands from the Mac Studio, and to transfer the image, and lidar, data files?
1 The iPhones will have to route commands sent over lighting cables from the Mac Studio to the appropriate application for camera, and LIDAR. What is the best way to do this routing?
To save time I will be basing the software on the iPhones on these sample projects which I will modify to meet the project's needs:
https://developer.apple.com/documentation/avfoundation/capture_setup/avcam_building_a_camera_app
https://developer.apple.com/documentation/avfoundation/additional_data_capture/capturing_depth_using_the_lidar_camera
Parameters I need to directly control from the Mac Studio are exposure times, F stops, which of the iPhones will flash. Each connected iPhone's camera must be triggered as simultaneously as possible.
I am very new to Swift, and OSX. I have read the Swift manual, and done the iOS App Dev Tutorials.
Post
Replies
Boosts
Views
Activity
I have a powered up, and logged in, iPhone 14 connected to a MacStudio by means of lightning cable.
This code snippet is being run in the MacStudio inside the XCode IDE:
@Published var iPhones: [IPhone] = []
var test: [EAAccessory] = []
var count = 0;
/// Update the iPhones list.
func Update(){
test = EAAccessoryManager.shared().connectedAccessories
count = test.count
iPhones = EAAccessoryManager.shared().connectedAccessories.map{ IPhone( Accessory: $0) } // ToDo: Filter for iPhone accessories only
}
The variable test is set to a value of 0 in the the Update() method. The iPhone 14 is not showing up in the test array.
On this webpage: https://developer.apple.com/documentation/externalaccessory/eaaccessorymanager
I see this:
Important
iPhone and iPad apps running on Macs with Apple silicon never receive connection notifications.
In the XCode IDE I have target set to Mac. Since I am running this in a Mac, and I have XCode set to a Mac target, I expected the result would be a Mac app running in a Max, and so I expected the above Important notice would not apply. Is my expectation correct? If not what has gone wrong here?
Does a MacStudio receive a connection notification when an iPhone 14 is connected?
Can EAAccessory methods be used in a MacStudio to communicate with an iPhone 14?
In this thread, eskimo posted code containing the line:
listener.service = .init(type: "_ssh._tcp")
I see in this document the type parameter is a service string, where its first substring identifies the application protocol, and its second identifies the transport protocol.
Where is it documented what the valid NWListener.listener.service string options are for these application, and transport, protocols?
On my Mac I made the mistake of reorganizing my development files. I renamed files folders, and application names, and moved some folders around to improve order, and better my ability to navigate the file structure. The result was a corrupted project that I could not fix all the errors on. So I created a new project that has the same name as the old, and copied the files into it. The result in the new after all the old project's files were copied to were these errors of the form:
Failed to register bundle identifier
The app identifier "com.example.com.Trial-iPhone" cannot be registered to your development team because it is not available. Change your bundle identifier to a unique string to try again.
No profiles for 'com.example.com.Trial-iPhone' were found
Xcode couldn't find any iOS App Development provisioning profiles matching 'com.IntOpSys.com.Bonjour-Trial-iPhone'.
(not the real domain name)
So I logged into my developer account at developer.apple.com to delete this certificate, and could not find a way to navigate in my account to where that is done. Is that doable? Where, or How?
I worked around the problem by appending a revision letter to the Bundle Identifier, such that it is now: com.example.com.Trial-iPhoneA . I would rather not have to do this when I already have an identifier to use, and also I do not like the idea of accumulating old, and never again used, certificates.
In the example code in this thread:
https://stackoverflow.com/questions/61235935/understanding-some-nwbrowser-i-managed-to-get-working
there is this line:
print("result ", result )
The second argument in the print statement, the "result" variable, is not a String type. It is instead a struct whose definition begins in line 10731 in the "Network" import file. Somehow the print function knows how to convert this into a string for printing to the terminal. I conclude, with some uncertainty, that the instructions for doing this conversion have to be defined in this struct. Where in this struct is the conversion defined? If not defined there, how is the conversion done?
The function:
browseResultsChangedHandler: ((_ newResults: Set<NWBrowser.Result>, _ changes: Set<NWBrowser.Result.Change>) -> Void)?
returns two Set type parameters. There is data in each element of these sets I need to display in a view. What is the best way to convert these sets to an array that can be iterated in a "ForEach" statement so they can be displayed in a View?
When I attempt to do it on a set directly I get the error:
Cannot convert value of type 'Set<NWBrowser.Result>' to expected argument type 'Range<Int>'
These are download links to zip files that contain Xcode 14.3 project files which are my attempt to establish USB communications with an iPhone 14 connected by lightning cable to a MacStudio:
https://www.mediafire.com/file/k3my6y94iyjobeq/Bonjour-Trial-iPhone.zip/file
https://www.mediafire.com/file/cof3b3w9tru1jd0/Bonjour-Trial-Mac-Enumeration.zip/file
I could not attach them here. This web interface's file browser had these files grayed out, so it was necessary to make them available on a file sharing site.
The Bonjour-Trial-iPhone.zip project files run on the iPhone 14. The Bonjour-Trial-Mac-Enumeration.zip run on the MacStudio.
I have the iPhone 14 project code working on the iPhone. I expect it should be advertising its presence.
MacStudio project runs, but does not find the iPhone 14. When I trace execution in file Bonjour-Trial-Mac-Enumeration.swift the "results" array is empty on line 65.
What is going wrong here? Is a type "_ssh._tcp" connection possible between a MacStudio, and an iPhone, over the lightning cable?
The Info.plist file is missing from my project as shown in this screenshot:
Yet the project has properties as the screenshot does show. So obviously the properties are being remembered somewhere, and I do not know where. As can be seen no paths to an Info.plist is currently set.
I need to create a new Info.plist file, and add it to the project. My concern now is about synchronization. If I were to do this by navigating to: File => New => File => Resource => Property List, and named it Info.plist, will this new property list file automatically synchronized with all of my current settings? Or would it contain only default settings, and synchronize my project's settings with those default settings?
I suspect the original Info.plist file was lost when I decided rename folders, and filenames, and had to copy everything into a new project to do that. I failed to copy over the Info.plist file.
Is there an easy way to convert a storyboard made for iOS to one made for a Mac? Failing that, is there an easy way to convert a storyboard to SwiftUI?
Is there a setting in the iPhone 14's iOS that allows the flashlight (torch) remain on simultaneously with the camera taking a still shot?
If not, is there an app that can do that?
On my MacStudio there are applications that start up when on login. I need to these not to be. No applications show up at:
System Settings => General => Login Items
Where else is there to look?
The startup apps that are opening are:
iPhone 14 Pro simulator
Activity Monitor
I believe the simulator is opening because I have been developing an iPhone 14 app with XCode. But once started, somehow, like the Sorcerer's Apprentice's brooms, it just keeps on appearing on its own, even if I have closed both it, and XCode, before shutdown. So now, to keep this off at startup, I need a sorcerer?
To learn how to do peer to peer communication I downloaded the TicTacToe example into my MacStudio from:
https://developer.apple.com/documentation/network/building_a_custom_peer-to-peer_protocol
I then loaded it into Xcode, compiled it, deployed to an iPhone 14 over a Lightning cable, and ran it. I developed code for the MacStudio in an attempt to communicate with it. The MacStudio at first detected the service but for some reason it has quit doing so.
The command: dns-sd -B _services._dns-sd._udpoutputs this as one of its lines:
A/R Flags if Domain Service Type Instance Name
Add 3 17 . tcp.local. _tictactoe
(The time stamp column deleted for clarity)
This line remains the command's output even after the iPhone the TicTacToe app has been shutdown, and after in the MacStudio Xcode, and the simulator it opens, is shutdown. In an attempt to find out what application is still advertising this Bonjour service I installed Discovery from:
https://apps.apple.com/us/app/discovery-dns-sd-browser/id305441017
When run the _tictactoe service instance does show in its list also also. But when I left click this item in that list to get a detail view of it I get a perpetual spinning wheel, and just to the right of it the message "Scanning...". No information is displayed. What does that mean in regard to what program is still advertising this service? What other ways are available to find this program so it can be shut down? Is it possible that this presence in that list, and in the output of the dns-sd is just a phantom vestige of an application that is not longer running? If this is a case how can the service offering be shutdown?
On the 4th question of: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/NetServices/Articles/faq.html
I see:
"you can ask the Bonjour to reconfirm the record"
I am basing my code on the TicTacToe example at:
https://developer.apple.com/videos/play/wwdc2022/110339/
I believe the DNS records which remains after the device that put them there shuts down is causing problems for me when again. Using the DeviceDiscoveryUI as in that TicTacToe example how are these records "reconfirmed" ?
In TicTacToe example there is in the override method "PasscodeViewController.viewDidLoad()" this snippet of code:
if let browseResult = browseResult,
case let NWEndpoint.service(name: name, type: _, domain: _, interface: _) = browseResult.endpoint {
title = "Join \(name)"
}
What confuses me:
The use of the "case" keyword without a switch statement.
The "case" keyword does not have a constant to compare with to decide if will branch here.
And what of the method call to NWEndpoint.service() being set equal to something? Is this actually defining what the service method will do when the system calls it?
I am still very new to Swift. Now I am learning about storyboards.
I added two View Controllers to the app by using the + icon in Xcode's Title Bar. Added one button to each of their screens, and then added a connectors (segues) between them, so that each button would navigate to the other screen. As soon as these connectors are added, each segue gets the error:
/Users/ ... /LaunchScreen.storyboard Launch screens may not have triggered segues.
So I figured at first that the first screen I added to the project by means of adding a View Controller must have been launch screen. So I remove the segues, I add two more screens in the same way, and make the same connections between these two new screens. The same errors appeared. It appears to me that Xcode considers every new screen added by dragging in a View Controller is a launch screen.
How do I make only the first screen the "Launch Screen"?