Showing posts with label Xamarin. Show all posts
Showing posts with label Xamarin. Show all posts

Thursday, November 16, 2023

_NativeStripFiles fails when building release build to upload Apple Store

I do not know if this is relatively known. This xcode-select --switch command.

Anyway, this is what happened to me. As it took sometime for me to figure this out. It is probably worth taking note.

First of all, I had multiple instances of Xcode installed on my Mac.

To be more precise, I have got a new Mac recently, a few months back. By then, the latest Xcode was 15. Naturally, I installed it.

Then I found that Visual Studio (I develop a Xamarin app) of that moment does not work hand-in-hand with Xcode15. I installed Xcode 14.3, keeping 15. They are sitting in different folders. In Visual Studio, I specify 14.3 as Apple SDK.

All went well. I built and published my app with the 16.4 SDK which comes with Xcode 14.3.

Sometime after that, I felt the need of using 17 SDK (I wrongly believed that this is required to support iOS17 devices). I found that with the Visual Studio update out in Oct 2023, I can use Xcode15 SDK (which is 17.0). The new build runs OK on an iOS17 simulator. So far so good.

To release to App Store, we need to build the app against an actual device, as you know. Then I have got this error:

xcrun: error: sh -c '/Applications/Xcode_14.3.1.app/Contents/Developer/usr/bin/xcodebuild ...

What?! Why this still tries a command of Xcode14.3, even after I have switched the Apple SDK to use to Xcode15!

I looked everywhere, Googled for a hint. No chance.

Helpless, I told myself how happens if I removed the Xcode14.3 installation folder.

Bingo! Now the error has changed and saying:

xcode-select: note: No developer tools were found, requesting install.

If developer tools are located at a non-default location on disk, use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools

With this message, I have come to know that I need to run the command to tell the system the Xocde I want to use.


Friday, September 30, 2022

WebAuthenticationSession "The UIWindowScene for the returned window was not in the foreground active state."

In my case, I got this error (from a certain point of time if remember well), when implementing an OAuth protected API access upon a screen opens.

My platform is Xamarin.Forms.

Originally, I was doing so in the OnAppearing event handler. Opening WebAuthenticator browser etc. that sort of things. But at one point, on iOS, it stopped working, giving the following exception:

Error Domain=org.openid.appauth.general Code=-3 "(null)" UserInfo={NSUnderlyingError=0x60000299a7f0 {Error Domain=com.apple.AuthenticationServices.WebAuthenticationSession Code=3 "The UIWindowScene for the returned window was not in the foreground active state." UserInfo={NSDebugDescription=The UIWindowScene for the returned window was not in the foreground active state.}}}

It appears that the WebAuthentication browser can only be shown and return thereafter, to a foreground active window.

OK. Let us move it to another event handler which is called when the windows appeared, rather than appearing.

There seems, however, no such an event available in Xamarin.Forms, in the PCL project.

On the other hand, the iOS native UIViewController has the event ViewDidAppear, and we can code the handler through the PageRenderer.

I am still a newbie in Xamarin development, was not sure if such is possible. But wow! It works like a magic! I moved the API calling code from the page code behind class OnAppearing method to the PageRenderer. Only for iOS. For Android, it remains in the code behind class.

So the "life cycle" is, on iOS, the ViewDidAppear method is called first since there is a custom renderer is implemented, while on Android, simply only the OnAppearing method is called.