Post not yet marked as solved
I have a SwiftUI app where I can sign in via Apple Sign In using Firebase Auth. This works completely fine on iPad and iPhone.
However when when running the app via catalyst on Mac, using Apple Sign In I get a crash with the following log.
_AuthenticationServices_SwiftUI/SignInWithAppleButton.swift:303: Fatal error: Attempting to present ASAuthorizationController from a SwiftUI
view not in a hierarchy. This should not be possible, please file
feedback. 2022-07-13 19:31:29.368989+0100 appname[93200:13915263]
_AuthenticationServices_SwiftUI/SignInWithAppleButton.swift:303: Fatal error: Attempting to present ASAuthorizationController from a SwiftUI
view not in a hierarchy. This should not be possible, please file
feedback. (lldb)
I am not sure what is wrong, I have checked Apple Documentation and am struggling to find a fix.
Apple Sign In Object:
import SwiftUI
import AuthenticationServices
import CryptoKit
@EnvironmentObject var store: Store
struct SignInWithAppleButtonView: View {
//Hashing function using CryptoKit
private func sha256(_ input: String) -> String {
let inputData = Data(input.utf8)
let hashedData = SHA256.hash(data: inputData)
let hashString = hashedData.compactMap {
return String(format: "%02x", $0)
}.joined()
return hashString
}
// from https://firebase.google.com/docs/auth/ios/apple
private func randomNonceString(length: Int = 32) -> String {
precondition(length > 0)
let charset: Array<Character> =
Array("0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._")
var result = ""
var remainingLength = length
while remainingLength > 0 {
let randoms: [UInt8] = (0 ..< 16).map { _ in
var random: UInt8 = 0
let errorCode = SecRandomCopyBytes(kSecRandomDefault, 1, &random)
if errorCode != errSecSuccess {
fatalError("Unable to generate nonce. SecRandomCopyBytes failed with OSStatus \(errorCode)")
}
return random
}
randoms.forEach { random in
if remainingLength == 0 {
return
}
if random < charset.count {
result.append(charset[Int(random)])
remainingLength -= 1
}
}
}
return result
}
@State var currentNonce:String?
var body: some View {
SignInWithAppleButton(.signIn) { request in
// You can change them if needed.
let nonce = randomNonceString()
currentNonce = nonce
request.requestedScopes = [.fullName, .email]
request.nonce = sha256(nonce)
} onCompletion: { result in
// Switch result
switch result {
// Auth Success
case .success(let authResults):
default:
break
}
case .failure(let error):
print("failure", error)
}
}
.frame(maxWidth: .infinity)
}
Login
import SwiftUI
import AuthenticationServices
import CryptoKit
struct login: View {
@EnvironmentObject var store: Store
var body: some View {
GeometryReader { geometry in
ZStack(alignment: .bottom) {
VStack(alignment: .center, spacing: 20) {
SignInWithAppleButtonView()
.signInWithAppleButtonStyle(.black)
.environmentObject(store)
}
}
}
}
}
Handler
class Store : ObservableObject {
func signInWithAppleHandler(credential: OAuthCredential) {
Auth.auth().signIn(with: credential) { (authResult, error) in
if (error != nil) {
// Error. If error.code == .MissingOrInvalidNonce, make sure
// you're sending the SHA256-hashed nonce as a hex string with
// your request to Apple.
print(error?.localizedDescription as Any)
return
}
print("Signed in")
if let user = authResult?.user {
// Fetch profile
let db = Firestore.firestore()
db.collection("users").document(user.uid).getDocument { [self] (document, error) in
if let document = document, document.exists {
//User exists now save that to current user
_ = document.data().map(String.init(describing:)) ?? "nil"
do {
self.profile = try document.data(as: Profile.self)
}
catch {
print("There was an error getting decoding Profile")
}
if self.profile != nil {
self.userAuthState = .signedIn
self.isNewUser = self.profile!.newUser
self.loadProfileImageFromFirebase(uid: profile!.uid)
}
} else {
// create profile
firestoreManager.createProfile(uid: user.uid, email: user.email ?? "")
fetchProfile(uid: user.uid)
}
}
}
}
}
}
Apple Documentation:
https://developer.apple.com/documentation/authenticationservices/signinwithapplebutton
Firebase Documentation:
https://firebase.google.com/docs/auth/ios/apple
Post not yet marked as solved
I built a MacOs app, and it works fine, but the problem happens when I achieve the project. When I tried from an old Xcode version (12.3) Macbook Pro late 13 it works But when I run from Macbook pro-2020 (M1 chip), the issue happened while archiving, and works fine while running, I use Xcode 14 beta.
The app is written in objective-c
I get this error:
/Users/usamafouad/Downloads/Oil Paint - Mac/Oil Paint App/frameworks/Source/Mac/GPUImageMac-Prefix.pch error build: Build input file cannot be found: '/Users/usamafouad/Library/Developer/Xcode/DerivedData/Oil_Paint-dywawlmfpsulhqapvsuiigxhgkrs/Build/Intermediates.noindex/ArchiveIntermediates/Oil Paint/InstallationBuildProductsLocation/@loader_path/../Frameworks/GPUImage.framework/Versions/A/Modules/module.modulemap'
Could you please help me, it's an urgent issue?
Post not yet marked as solved
When I hover the mouse over the NSTextAttachment image inside the UITextview, it should show this option to MarkUp. All native app including Notes, TextEditor, Mail have this behaviour:
I think, by default, NSTextView will show the NSSharingServicePicker button when you hover over an image inside the text view. That’s true even for custom image-based NSTextAttachments in the attributed string.
But it is not showing the button for UITextview in MacCatalyst. Also NSSharingService class is limited to MacOS only.
Are there any alternative way to achieve this in MacCatalyst?
Post not yet marked as solved
UITextview's Spellchecker seem not to detect spells and show red dots at odd position in MacCatalyst:
It does work well in iPhone and iPad though.
I've activated the Spellcheck through storyboard, also tested with both Normal and Attributed strings. Even tried disabling the scrolling. But nothing seems to help!
Does any one know about this behaviour?
Post not yet marked as solved
I'd like to handle it so that it doesn't quit even if I press the Dock Icon's "Quit menu" on Mac Catalyst.
Please let me know how to use the delegate func below on Mac Catalyst.
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply
Post not yet marked as solved
I am building an iOS / Swift app for my M1 Mac in XCode by selecting the build target of "My Mac (designed for iPad)" from the drop down list. I was wondering if it is possible to access local files on my mac ( e.g. /Users/Downloads etc ) via the usual FileManager APIs ( or any other way ) I'm NOT trying to access files in the app bundle or app documents directory.
I get a permissions error when trying to read a file or directory.
I'm pretty sure I had done this in the simulator before, but that approach won't work here because I use some pre-compiled arm64 only libraries. I also tried Mac Catalyst but had similar build issues around my pre-compiled libraries.
Maybe there is a way to use arm64 simulator on the M1?
Thanks
Post not yet marked as solved
We are building an app that support Mac Catalyst and network extension is included in.
We don't know why the compiler throw this error:
Network extensions are not available when building for Mac Catalyst.
The documentation related to network extensions (in this case NEFilterDataProvider) in apple docs said explicitly that Mac catalyst is available.
@eskimo @meaton please let me know if there's a bug with it.
https://developer.apple.com/documentation/networkextension/nefilterdataprovider
Post not yet marked as solved
Hello there,
Does the UNNavigationController have to be the rootViewController to get the automatic conversion to an NSToolBar? For example, I have a UITabBarController which contain several views, each with their own UINavigationController but they are not converting to NSToolBars. Is this a beta 2 limitation?
Also, the sample code linked for session wwdc2022-10076 won’t compile for macOS vis Catalyst. https://developer.apple.com/documentation/uikit/app_and_environment/supporting_desktop-class_features_in_your_ipad_app
Thanks,
Matt
Post not yet marked as solved
Issue
After an Update to 12.4 my AVCapture session is using between 70-90% CPU
That code is just a simple capture session in a Mac Catalyst App with the webcam of the Mac. The session calls an empty func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) and nothing more is happing in the test app I tried. Also no rendering of the stream.
My test code ran with 10-15% CPU usage a week ago, before I made an update today to macOS 12.4 - with rendering into a Metal view maybe 20-25%
To reproduce:
take AVCam project https://developer.apple.com/documentation/avfoundation/capture_setup/avcam_building_a_camera_app
Set checkbox for Mac Catalyst Support in General
run on Mac
The original sample code from Apple is also running with the same high CPU usage.
But even my AVCaptureSession code ran a week ago at about 15% which might even be too much.
I have tested this on a 2019 Intel MacBook pro and also tried it on a macOS 12.4 iMac which did result in the same high CPU usage with all the test apps.
Update to macOS 12.5 Beta 3 did also not help. But I know it ran better with macOS <12.4 and also almost 100% CPU even with 800% overall available is too much for just camera capture
Profiling in Instruments
Insturments is showing me with the heaviest stack trace a lot VN calls with object detection - is this the camera autofocusing? Do I need to put more options for the capture device? I don't call anything from the Vision Framework - is this happening automatically?
It looks like this, feels like a lot of work for just the Mac webcam:
what to do?
Is this a problem with macOS 12.4? Do you have a better running Capture session on 12.4 and what is needed to archive that? Could this be a Catalyst problem? Is this a bug which needs a bug report with Apple? I can't really go back to a previous version, and it would be neat if the code would also work on macOS 12.4 haha
I have 2 Apps.
A sandboxed native Mac App written in AppKit/SwiftUI.
A Catalyst App.
I would like them to be able to communicate with each other. I assumed I would be able to do this using a shared App Group but I can't get it to work and I think this is because the App Group naming conventions appear to be different.
As far as I can make out:
A Mac App uses App groups prefixed with the team ID
A Catalyst App uses the iOS App groups which are prefixed with group.
I have tried multiple combinations of different prefixes to try and make this work but without success.
I have been "testing" this by using UserDefaults(suiteName: appGroup) and then attempting to read write values between the 2 Apps but without success so far.
My questions are:
Is sharing an App Group between Catalyst and native technically possible?
If it is possible what is the magic combo of App Group prefixes that makes it work?
If it is not possible then do I have any other options for communicating between a sandboxed Mac App and a Catalyst App?
Post not yet marked as solved
With a simple SwiftUI layout that presents a list of tasks that can present a detail view, there appears to be no way to configure the toolbar when running on Mac Catalyst.
Presenting in a NavigationView with columns gives the sidebar a toolbar that can be configured but the detail view will not have one and there is no way to add one. It will, instead, default to using iPad style toolbars which are inappropriate for macOS.
.windowToolbarStyle is unavailable to Catalyst apps.
Will this be addressed in macOS 13/iOS 16?
Post not yet marked as solved
We have several Mac Catalyst apps that use UIPrintInfo and UIPrintInteractionController to support printing. Both of these classes are marked as available on Mac Catalyst 13.1 in the documentation and we do not receive any errors or warnings using them in our app. We have successfully uploaded to App Store Connect recently with apps that use those classes, but now are receiving error messages from App Store Connect complaining that the use of these classes is non-public API and receive the ITMS-90338 error, even though no code has changed. Is this an issue on the validation side, or are these classes no longer supported on Mac Catalyst? Thanks in advance for any help!
Post not yet marked as solved
Hi,
I enabled Mac Catalyst (macOS12.1) for an app, set Optimise Interface for Mac with the following code. The code can be compiled with "Build Succeeded" and can be run successfully on an M1 Mac. However the editor will flag out the following:
'horizontalSizeClass' is unavailable in macOS
and with build time issues. If I use UIViewControllerRepresentable it will give
Cannot find type 'UIViewControllerRepresentable' in scope
The app does run ok. Am I missing something?
import SwiftUI
struct ContentView: View {
@Environment(.horizontalSizeClass) var horizontalSizeClass: UserInterfaceSizeClass?
var body: some View {
if horizontalSizeClass == .compact {
Text("Compact")
} else {
Text("Regular")
}
}
}
Thanks in advance.
Hi,
I've assigned contextual menu to my tableview rows which seems to focus cells background with blue ring in MacCatayst.
If tableview style is Plain or Grouped, it focus ring appear as it should but in InsetGrouped type tableview, it seems to be broken.
I've tried disabling the focus with :
func tableView(_ tableView: UITableView, canFocusRowAt indexPath: IndexPath) -> Bool { return false }
And
tableView.selectionFollowsFocus = false
But no luck disabling it.
Anyone has any Idea about this behaviour ?
Post not yet marked as solved
I'm working on an iPad app, which I want to be able to run properly on the M1 Mac. I am not using Mac Catalyst because I am using OpenGL, which is not available for Catalyst. Instead, I am targeting "My Mac(Designed for iPad) when I build for the M1 Mac.
I would like to know when my app has been placed in full screen mode (when running on the M1 Mac). MacOS (AppKit?) provides the "NSWindowDidEnterFullScreenNotification" to help with this.
In general, I'd love to be able to access these "NSWindow*" notifications from within my iOS app, but specifically, I get the error: "Use of undeclared identifier 'NSWindowDidEnterFullScreenNotification' when I use "[NSNotificationCenter defaultCenter] addObserver" to get notified when my app goes full screen.
Any ideas as to how I can bridge this gap between iOS and MacOS and get notifications from MacOS, without resorting to Mac Catalyst? This capability would be extremely useful.
MacOS M1 machines can run iOS applications.
We have an iOS application that runs a fullscreen metal game. The game can also run across all desktop platforms via Steam. In additional to Steam, we would like to make it available through the AppStore on MacOS. We'd like to utilise our iOS builds for this so that the Apple payment (micro-transactions) and sign-in processes can be reused.
While the app runs on MacOS, it runs in a small iPad shaped window that cannot be resized. We do not want to add iPad multitasking support (portrait orientation is not viable), but would like the window on MacOS to be expandable to full screen. Currently there is an option to make it full screen, but the metal view (MTKView) delegate does not receive a drawableSizeWillChange event for this, meaning the new resolution of the window cannot be received.
Is there another method of retrieving a window size change event in this context? What is the recommended way of enabling window resizing on MacOS but not iPad for a single iOS app?
Post not yet marked as solved
The WWDC '17 session for core spotlight said QLSupportsSearchableItems is only for "shoebox" apps and explicitly said it's not for document-based apps, but when trying to upload my UIDocumentBrowserViewController-based MacCatalyst app with a quicklook extension (the view-controller-based quicklook preview works great) to App Store connect, it prevents me from uploading without a QLSupportsSearchableItems keys in my quicklook extension's info.plist, and it prevents me from uploading it if the value is false (0).
Is the app store validator correct, and I must have this key and it must be true?
Do I have to implement func preparePreviewOfSearchableItem(identifier, and if so, can I just have it always fail?
If it can't fail, how would I get a sandbox url for the document from a searchable item identifier?
Also, Xcode won't find anything when I search for QLSupportsSearchableItems, which is not so much ironic as it is face-palmy.
Post not yet marked as solved
Hi,
I'm trying to define the style of an UIButton using UIButton.Configuration in a Mac Catalyst app.
I was able to configure the component as I want except one thing.
I want to change the style of the button when the window is not active.
The default filled style automatically do this.
For example below you can see a button configured with
UIButton.Configuration.filled().
If the window become inactive (for example by activating another application) the color of the button change, like so:
Now, If I configure a button with this configuration:
var configuration = UIButton.Configuration.plain()
configuration.background.strokeColor = .gray
configuration.baseForegroundColor = .red
configuration.baseBackgroundColor = .clear
the button display with this configuration when the window is active:
but also when it's not active:
I want to change the text color from red to gray when the window is not active.
Someone know how to do it?
Thank you
Post not yet marked as solved
Hi,
The following code allow to build an image from an UILabel:
let label = UILabel()
label.text = "test content"
label.backgroundColor = .white
label.layer.cornerRadius = 10
label.layer.masksToBounds = true
label.sizeToFit()
let format = UIGraphicsImageRendererFormat()
format.scale = 5
let renderer = UIGraphicsImageRenderer(bounds: label.bounds, format:format)
let image: UIImage? = renderer.image { rendererContext in
label.layer.render(in: rendererContext.cgContext)
}
This works perfectly on iOS but on Mac Catalyst the label text is very blurry as you can see in the image below.
Both images are created with the same exact code and have the exact same resolution of 460x103.
On top the iOS version and on bottom the Mac Catalyst version.
Note that not all of the image is blurry, but only the text. In the code I set a corner radius of 10 and you can see that the corner is rendered with an high resolution, like the iOS version. It's just the text that for some reason is blurry. It's like if the label text is rendered with a scale of 1 and then scaled up.
Someone know why? There is something I can do to improve the rendering of the text?
Thank you
Post not yet marked as solved
iPadOS apps running via Catalyst on macOS now insert a tab character in UITextField when the tab is typed. When running in macOS 12.2 typing a tab character focused on the next UITextField.
The same code/app running on iPadOS (device or simulator) responds by focusing on the next UITextField when a tab is typed.
Was this a purposeful change in Catalyst? I have not been able to find anything that talks about this. And it is impacting the usability of our app in cases where we have multiple UITextFields present.