UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

iOS App using Document Template when run on M1 Mac "Designed for iPad" shows No Available Windows message

Forums > SwiftUI

My understanding is that we can create an iOS (specifically iPadOS) SwiftUI app that can run as-is (without any source code changes) on M1 macs. I realize there may be some UI issues/differences.

In other words, I'd like to develop a 100% SwiftUI "iPad App" but allow users to run it on their M1 macs. Is this possible?

I have an M1 mac mini running macOS 11.3.1 and Xcode 12.5. When I start a new SwiftUI app selecting iOS and the Document App Template and then try to run it as a iOS app directly on my M1 mac mini, after selecting "New Document" or an existing file, I then get no window. If I right click on the app in the dock and select Show All Windows, I then get a very small message window that says "No Available Windows".

For Deployment settings, I have iOS 14.5 selected and only iPad checked.

I have tried specifying a frame (in different source files, different locations, with different options), but still can't get a window (the TextEditor in particular) to display.

How do I get a window ("the app" to display) in this scenario?

2      

by and large you can reuse lots of code between iOS and macOS with SwiftUI. There are some differences though. So the 100% wont happen, but you can mostly do it.

Are you using WindowGroups?

One way to narrow this down is to make a new Mac app project or target using the Mac template. Do that in your workspace where you have the iOS code. That should work out of the box and show a working mac app, with a window group and a contentView containing a text priting hello world. You should be able to generate new windows containing this view from the File->New menu item.

From there you can drop your iOS code in and see what compiles or not. Replace the contentView of that app with your own root view, which might well be contentView.

If you are using a sidebar on the iPad it should appear on the Mac version. Mostly things will work, however there are iOS features that are not in iOS and ( to a lesser extent) vice versa. And to get a proper mac app you may have to add some extra menu handling.

To handle this you can add

#if os(macOS)
 #else
  #endif

around the code to make it compile or to add OS specific features. Most UI should work out of the box though.

2      

Just to be super clear, at this point I'm using the Document App template code only. No additional code.

I'm pretty sure in one of the 2020 WWDC videos it was said something like "iOS apps can run without any modification on M1 macs". I may be remembering this incorrectly. I'm very much hoping to avoid using the (compiler directives?) #if os stuff, but I'm aware of this option.

For what it's worth... I get these messages in the output, which are well beyond my knowledge: 2021-05-22 10:01:05.437386-0500 iOSonMac[1799:90528] IOMFB: FigInstallVirtualDisplay not found 2021-05-22 10:01:05.838177-0500 iOSonMac[1799:90528] Did present bridged document browser 2021-05-22 10:01:09.148729-0500 iOSonMac[1799:90899] Scene destruction request failed with error: (null) 2021-05-22 10:01:09.412260-0500 iOSonMac[1799:90528] Metal API Validation Enabled 2021-05-22 10:01:09.471934-0500 iOSonMac[1799:90528] fopen failed for data file: errno = 2 (No such file or directory) 2021-05-22 10:01:09.471970-0500 iOSonMac[1799:90528] Errors found! Invalidating cache... 2021-05-22 10:01:09.532541-0500 iOSonMac[1799:90528] +[MTLIOAccelDevice registerDevices]: Zero Metal services found

2      

the iOS apps that run on the M1 chip run as iOS apps, same UI. Just like the simulator really.

If you want that just publish to the app store.

2      

eoinnorris - Thanks for the comments.

I'd like to test my real iOS (for iPad) Document App as an iOS app on my M1 mac. Any idea how to get the initial window to display (after selecting New Document or selecting a text file)? I suspect I may be missing one settings checkmark or something else that may be obvious to most everyone else.

After I got my M1 mac mini, I first tried my app (in development previously on an Intel mac mini), but didn't get a window (after selecting New Document or selecting an existing text file). That's when I figured I should start from scratch with the iOS Document App template, but even that doesn't give me a window.

Ironic thing is that I got the M1 mac mini so I could test this. Not bitter. Just hopeful for a fix!

2      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.