How can I correctly provision an Xamarin Forms iOS app with (or without) a ShareExtension? - ios

I've had hours and hours of problems with Xamarin Forms iOS provisioning for my app with and without a ShareExtension.
I have had it working in the past with various combinations and permutations of configuring simulator/device/debug/release/certs/ids/auto or manual provisioning...etc. which I didn't record at the time, but it is very fickle and unpredictable and there are a large number of moving parts.
As such the following is a systematic record of the steps I've taken with questions when things have behaved in unexpected ways and my app hasn't run or deployed correctly.
NOTE: The following steps are for development but if I can get dev running, I will then continue to update this question for the distribution process.
The 3 main elements and their interaction that causes me most confusion are below:
Online Apple Developer Portal
MacOS with Xcode and keychain
Windows Visual Studio Xamarin
STEPS TAKEN
A) DELETE EVERYTHING FOR A FRESH START
I deleted all my certificates, identifiers and profiles from the above 3 (with the exception of the main app id which is in the app store and couldn't be deleted). For the physical devices I removed via:
Xcode
VS (Win)
relevant folder locations on Win and Mac
keychain
B) CREATE A DEV CERT, AUTO PROVISION, RUN THE APP
In visual studio login to my Apple account via Options -> Apple Accounts
Then View details -> Create certificate
Outcome: This works fine. The new cert appears on Windows, Mac and on the Apple Dev Portal. The app runs successfully with auto provisioning.
However, no profiles can be seen in the online Apple Dev Portal - why? - UPDATE: They now appear around 30 mins after they were created
C) ADD A SHARE EXTENSION
Add ShareExtension project and reference it to my main app.
Use Automatic Provisioning
Outcome:
Auto Provisioning gives: "Invalid request, Service mapping to the requested URL is not available.". As a result I go into the Apple Dev Portal and manually create an ID, then retry Auto Provisioning, which is now successful. Try to run the app again but: app runs ok, but share extension can't be seen.
I have double checked:
Main app has ShareExtension reference
Main app info.plist has:
<key>NSExtensionPointIdentifier</key><string>com.apple.share-services</string>
App group is set in VS for both projects and both App IDs in online portal
What is going on here?
---UPDATE---
D) TRY MANUAL PROVISIONING INSTEAD
I did the following:
Created two manual provisions, one for container and one for extension
As Visual Studio Apple Account didn't reflect these, I downloaded the provisions from the portal, put them in the relevant Windows folder and now they appear
Tried to build:
What is happening here?
Why is the error about Auto Prov, when I have clearly set it to Manual Prov
Why is the 2nd error about the profile not found when it shows in above drop-down, and in the portal that it very clearly exists?

After much pain, I have finally stumbled upon a combination of steps that seems to work. Given the unpredictable and what seems to be buggy nature of VS, I cannot guarantee that this will work for everyone, or even guarantee that it will even work for me again for my next build, but it has been working for the past 12 hours or so over several builds and deployments. I can only pray that it continues to work.
Anyway, here are keypoints that I used to get it working:
Follow my step A) above and delete everything as often as possible. New certs and profiles in the Portal tend to accumulate after a while, possibly when creating via the Portal, Xcode and VS, so it's good to remove everything every so often and start from afresh.
VS for Mac is I believe a much cut-down and less capable version of VS for Windows. As such when doing development, VS Windows is a far better tool, if you can get around development provisioning. I struck upon a combination where I created the Cert in VS Windows (this is preferable to creating in the Portal because it avoids having to download the cert and ensure it is installed correctly on your local machine), and used Automatic provisioning for debug that seemed to work for me. It didn't work for a while, nor did manual provisioning, but somehow for now its working.
Once the app is stable in debug mode, and you want to deploy to App Store Connect:
a) manually create your distribution certs on Xcode, and create profiles in the portal
b) move your code onto VS Mac
c) build and archive using the new distr profiles
d) Goto Xcode -> Window -> Organizer
e) Locate your archive and click Distribute App
f) From here the wizard will guide you again into selecting relevant profiles for distribution for both container and ext and give you a lot of feedback on the upload process until the upload is complete.
Anyway, once again, no guarantees that will work for all, but it's working for me now.
Cheers!

I have also tried using Visual Studio 2022 to finish an iOS development process but cannot reproduce your stepD. The following is the main step:
1. Create App ID for container and extension, Create an AppGroup ID
This is for my container, with App Group enabled.
This is for my extension App ID, also enable the same App Group.
2. Create certificate and profiles
You could create a iOS development certificate in Visual Studio or in Apple Dev Portal. Then you could find it in your Certificates.
3.Generate your profiles for both container and extension. (Remember to register your physical device in Devices, and in your profiles, includes your device on which your app is installed)
This is for my container with the container's App ID
this is for my extension with the extension's App ID
4. In Visual Studio, select the proper provisioning file.
Before this step, also download the provisioning files from the portal as VS does not automatically download them. Put them in the relevant Windows folder.
This is for my container, with the certificate and the provisioning file
This is for my extension:
Also, my info.plist for container and extension:
5. Pair to mac and run on your device
Now the App could install on your device~

Related

How do you distribute a Xamarin Forms iOS archived container app with a share extension?

I'm having problems archiving my Xamarin iOS app which has a Share Extension.
I am using Visual Studio 2022 for Windows paired to a Mac.
I have created:
a distribution profile in App Store Connect
identifiers for app and extension with App Group entitlements
App Store profiles for app and extension
Bundle Signing for Extension:
Manual Provisioning
Distribution: Automatic
Provisioning Profile: No matching profiles found (Why not found?)
Bundle Signing for MainApp:
Manual Provisioning
Distribution: Automatic
Provisioning Profile: MyAppName
In addition, in my Identifiers I have an additional record which I did not add myself:
XC com companyname MyAppName Share (Where has this come from?)
When I try to archive I get the following errors:
Cannot create an IOS archive 'MyAppName'. Process cannot be executed on XMA server.
"ditto" exited with code 1
I've searched for documentation or examples on how to distribute a Share Extension, but can't find anything helpful. I've also been able to successfully upload an archive to the store without the Share Extension attached.
What is going on here?
UPDATE
Just tried to release through VS on Mac, and getting a whole lot of new errors. The Mac VS is horribly designed and seems like it was just thrown out as an afterthought. There is no proper output window for archiving issues; the issue messages are squashed, non-wrapped into the single line status bar at the bottom of the screen in a way that I need to open the application on a large monitor to see; I have no idea whether they are warnings or errors and if the build has stopped or not.
I hope the suggested response is not: release it on VS Mac.
Here, i would like to share the way of publishing my app with share extension using VS for MAC, for the purpose of helping others.
First, create iOS Distribution Certificate in your Apple Developer account. Before doing this, you have to generate a Certificate Signing Request file in your KeyChain.
Second, if you use AppGroup, you should generate an App Group ID, which would be used for your share extension as well as its container app. Then in Xamarin Forms project, for your share extension and its container, both set the App Group ID in the Entitlements.plist.
Third, generate App IDs for both your app and share extensions. In Capabilities, you have to configure to choose your AppGroup in previous step.
Then, generate profiles for both your container and share extension. You should select the proper iOS Distribution Certificate and App ID. Then download and refresh your profiles.
Now in Visual Studio for MAC, you could select profiles for your App and extension respectively in iOS Bundle Signing. Then you can archive them for publishing~

Error adding Apple Developer Account: authentication service is unavailable

I’m trying to add an apple developer account to VS 2019 Community ver. 16.9.2 for Windows.
Once I set the Apple ID and Password and click on Login, I get the following message:
“There was an error while trying to log in: Authentication service is unavailable.”
The Apple ID and Passwords are correct, in fact, if I type in the wrong credentials then Visual Studio complains about invalid id/password combination.
I disabled the firewall during the process so this should not be a connection issue.
Also, I made sure I have no pending agreements on Apple Store Connect. My apple developer account is valid and has no issues. In fact, I can use the same account on xcode just fine.
Is there some workaround?
THIS ISSUE IS FIXED IN THE 16.9.6 VISUAL STUDIO UPDATE !!!
(old workarounds)
There are some workarounds but none of them worked for me and updating to the latest version didn't help either (Visual Studio 2019 16.9.4). For as far as I know this issue persists even on version 16.7.5 of VS2019. For some people the workarounds seem to work so I will list them here so hopefully some of us can get on with our projects.
Workaround 1 (offered by Xamarin team):
Close Visual Studio 2019
Delete the following folder %LOCALAPPDATA%\Temp\Xamarin\XMA
Open project -> clean sollution
Set Automatic for bundle signing in the iOS project settings
Rebuild
(- if it doesn't work try again after restarting pc)
Workaround 2:
Delete your apple account from VS2019 through Tools–> Options --> Xamarin–> Apple Accounts
Sign back in again
Download your provisioning profile from developer.apple.com account to you pc
Copy and paste it into: \Users\YOUR_USERACCOUNT\AppData\Local\Xamarin\iOS\Provisioning\Profiles
If it doesn't work, perform in combination with workaround 1
Workaround 3:
Delete apple account from VS
Remove certificates from AppData\Local\Xamarin\iOS\Provisioning\Certificates
Remove profiles from AppData\Local\Xamarin\iOS\Provisioning\Profiles
Add Apple account
Set to Automatic Provisioning and select team, it will error again but will reinstall the certificates
Manually download provisioning profile and copy it to - AppData\Local\Xamarin\iOS\Provisioning\Profiles
Run the archiving process should error out again but the “id” or name of the provisioning will be displayed in the error
Rename the provisioning file to match and rerun archiving.
As I said these workarounds don't work for me but I hope they do for you. If it doesn't then you're in the same boat as me and you're going to need to follow this thread:
https://developercommunity.visualstudio.com/t/Error-adding-Apple-Developer-Account:-au/1380749?viewtype=all
I was able to use a combination of several workarounds from Michael's answer to get the app signed and deployed on an iPhone (for debugging). Here are the steps in correct order that worked for me:
Set Automatic for bundle signing in the iOS project settings
Delete your apple account from VS2019 through Tools–> Options --> Xamarin–> Apple Accounts
Close Visual Studio 2019
Delete the following folder %LOCALAPPDATA%\Temp\Xamarin\XMA
Delete all "obj", "bin" and ".vs" folders for the solution
Download your provisioning profile from developer.apple.com account to you PC and save it to %LOCALAPPDATA%\Xamarin\iOS\Provisioning\Profiles
Open Visual Studio 2019
Add your apple account from VS2019 through Tools–> Options --> Xamarin–> Apple Accounts
Build. It will error out while signing the app.
Look at the error. It should specify the expected file name for your provisioning profile. The file name is a long string of hex digits with extension ".mobileprovision".
Go to %LOCALAPPDATA%\Xamarin\iOS\Provisioning\Profiles and rename your provisioning profile file into file name from the error message.
Build again. It should work now!
I just went through the exact same problem and it took forever to work out. I'd had my app running locally and debugging on my iphone just fine. A few months later this bug popped up... I needed to simply update iTunes. iTunes handles the handshake stuff for your iOs devices and Windows.

Visual studio unable to locate provisioning profiles for Xamarin.iOS

I am trying to setup my environment to deploy my app to a real IPhone for testing because I dont want to work with simulators and etc. It apparently requires provisioning profiles. I dont have a paid apple developer account and I learned that it is not required. These are the steps I have done so far:
Open xcode on my mac go to Preferences> Accounts> Add new Apple ID. I added one of my apple IDs.
I then added a new project select a team and selected necessary options to create the project
I went to project propertiesi setup the iOS version.
I went to signing and enabled automaticly manage signing. It did something and created a certificate for me.
I deployed the app once to my phone which worked fine.
I later opened visual studio on my windows machine.
Paired my mac with my visual studio.
Went to info.plist and copied my bundle identifier from xcode to visual studio.
Enabled Manual provisioning but no developer profiles. Restarted VS but no luck
I basically followed this site
https://learn.microsoft.com/en-us/xamarin/ios/get-started/installation/device-provisioning/free-provisioning?tabs=windows
I tried without selecting a specific provisioning profile (it was in developer (automatic))
It seemed to be going well until it gave this error
error MT1007: Failed to launch the application '/Users/xxxxxxx/Library/Caches/Xamarin/mtbs/builds/App8/4ae6e8b79af6f5c06054809bff907c4f900782cdb32378817eb5bbdd1fa2e996/bin/iPhone/Debug/device-builds/iphone11.8-14.2/App8.app' on the device 'iPhone': Failed to launch the application 'com.xxxxxxxxxxxxxx.App8' on the device 'iPhone': Invalid Service Error (error: 0xe8000022) 0
I found the solution to my problem. The site https://learn.microsoft.com/en-us/xamarin/ios/get-started/installation/device-provisioning/free-provisioning?tabs=windows showed illustrations of choosing specific provisional profiles
However I didn't get this kind of choosing
Mine had
Developer (automatic)
No profiles found (or something in english: my VS is not in english)
but apparently it is not required to choose the exact profile from VS. I was able to deploy the app by just compiling the app as usual (after following the steps of course). However there is a problem with launching the app which requires me to go to settings and trust my apple id or something which is not important.

iOS app upload to iTunes Connect results in Invalid Signature issue

I'm working on a hybrid mobile app project (Ionic framework) and releasing to Android, iOS and web. This issue concerns only releasing the application on iOS.
I ran into an issue whereby I suddenly started getting the following email from iTunes Connect after building, archiving and uploading my iOS app to App Store from Xcode.
App Store Connect: Your app "YourAppName" (Apple ID: XXXXXXXXXX) has
one or more issues
Dear Developer,
We identified one or more issues with a recent delivery for your app,
"YourAppName". Please correct the following issues, then upload again.
Invalid Signature - A sealed resource is missing or invalid. The file
at path [YourAppName.app/YourAppName] is not properly signed. Make sure you
have signed your application with a distribution certificate, not an
ad hoc certificate or a development certificate. Verify that the code
signing settings in Xcode are correct at the target level (which
override any values at the project level). Additionally, make sure the
bundle you are uploading was built using a Release target in Xcode,
not a Simulator target. If you are certain your code signing settings
are correct, choose "Clean All" in Xcode, delete the "build" directory
in the Finder, and rebuild your release target. For more information,
please consult
https://developer.apple.com/library/ios/documentation/Security/Conceptual/CodeSigningGuide/Introduction/Introduction.html
Best regards,
The App Store Team
I tried everything I could find on the internet regarding this issue:
Checking over my certificates, provisioning profiles, recreating them, updating Xcode, building the project again, made sure I'm using a distribution certificate not an ad-hoc certificate, verified the code signing settings in Xcode were correct, verified the bundle was built using the Release target, tried the "Clean All" option, deleted the "build" directory in the finder and rebuilt the release. In short - I tried everything I could find by Apple regarding this issue, also looked up the same issue in StackOverflow and tried a huge variety of the recommended solutions. I tried all of those options multiple times over to make sure I didn't miss anything.
Nothing worked...
Also a note that I was able to upload to App Store without any problems before. There hasn't been any changes to the project which could result in this Invalid Signature issue arising - no certificates have expired, no new ones have been created, no new provisioning profiles have been created. The same profiles and certificates were used which worked just fine some time ago. iTunes Connect just suddenly started responding with this issue.
What else can I try?
I was sceptical at first when I tried this solution but this actually solved my issue.
Find a spare USB stick or an external hard drive.
If your Mac's filesystem is APFS format the external volume using a HPFS Mac OS Extended (Journaled) file system. Move your project over to the freshly formatted HPFS external volume and rebuild it over there. This is important as if you build it on your Mac's APFS volume and then move it over to your HPFS external volume to archive and upload in Xcode this will not work!
The project needs to be built, signed, archived and uploaded ON the HPFS volume.
The uploading to App Store should now work again. It worked for me, hope it works for you as well.
See more information on the solution here

Failed to get the task for process [duplicate]

I have the following error when I try to run a new project on my ipod:
Error launching remote program: failed to get the task for process 312.
The program being debugged is not being run.
I've read about Entitlements.plist, and I've tried to add the get-task-allow, but then it doesn't let me compile because of a code signing error. I only have a development provisioning profile, so it's not the same as the people who were trying to debug the distribution build (I'm also in the debug build, so that isn't a problem).
Old projects build and run fine on the ipod, just new projects.
I've tried restarting both xcode and my ipod, but it doesn't help.
I have no more ideas on how to build/run new projects on xcode, so any help is much appreciated!
Oh, and I'm using an iPod 3G with iOS 4.0.1. Xcode is 3.2.3 (64-bit).
It turns out that using a different provisioning profile (one with a wildcard rather than one without) solved this issue.
The key point is to use a Developer profile rather than a Distribution profile.
Check that you're doing signing using a development provisioning profile, not a distribution one.
This error happens when you have set Distribution Provisioning profile in code signing. Change it to Developer Provisioning Profile, then it will work. Worked for me for Xcode SDK 4.5.
There is also a case that your error would happen.
If an app with same Bundle Identifier is launched at background ( probably an App Store version ), Xcode debugger will not know which App it should attach to. To solve it, remove/uninstall the App Store version, and click Run in Xcode again.
The same story can apply if you once build the app with a bundle id then you changed the project bundle id and still kept both app versions. make sure you remove the old one.
If your certificates are not quite right or have become not quite right, this problem can start to happen and you can go round and round playing with provision and entitlement files to no effect. (In nearly all cases, you don't need an entitlement file.)
I'm talking here about debugging on a tethered device in "debug" mode, not any sort of "release" mode.
Here's how I finally determined this was the problem and fixed it:
1) Try to create the simplest Xcode project possible and in Target...General set it up for your "Team". (If you find this impossible to do, that already is a sign of this sort of problem.)
2) Tether your device and try to run on it. Normally, this would go smoothly, but if the opening screen appears on your device for a second or two and then the app crashes and Xcode says it can not attach to some positive task id, then you may have the sort of problem I had.
3) So I then went to another Mac with Xcode and did the same thing, letting Xcode 5 automatically get the needed credentials. (I'm using a "wild card" * app id for all of this.) In my case, much to my surprise the simple app I created on the new Mac ran on the tethered device just fine keeping up its opening screen indefinitely. What a relief. So I then went to keychain access on the new machine, exported all of the relevant keys into one file and then exported the relevant certificated to a .p12 file. I also made a copy of the new working project to take back to the first Mac.
4) Back at the first Mac using the app for the second Mac, it had trouble with the Team ID when I looked at the Target...General screen. Your symptoms might be different, but the point is I couldn't rebuild the app from the second Mac on the first Mac.
5) So I then opened up Keychain Access (possibly not necessary) and double-clicked on the files I brought over, first the one with the keys and then the one with the certificate, providing the p12 password when requested. (Some of this may not actually be necessary, but I'm not sure which and I am describing what worked for me.)
6) I did step 4 again and this time it worked fine! I then found that the other programs that were giving me the "failed to get task" problem now worked fine, too. I just wish I could get back all the time I lost before I tried the process described here.
Conclusion, something was wrong or had become wrong with the certificates or the keys on the first Mac. It was subtle enough that I could still do builds, make ad hoc releases, etc. but I could not run on a tethered device. Though I don't think it is a factor, I was using a corporate developer account and this Mac was set up to do development for several other developer accounts (and these did not display the problem).
After Xcode 5.0 tried and failed (it hung) to update certificates, ... which it suggested me to do. All I did then:
Restart Xcode 5.0
Open Window > Organizer
Select Devices at the top
Select my device (which had a green bullet)
Click the (+) Add to Member Center at the bottom and follow the few simple steps
Go to the Apple Developer Center and make sure that your developer certificate has not expired. Mine had expired so I renewed it and then went back into Xcode (5.1.1) and under accounts preferences I viewed the details of my apple account and hit the little refresh button at the bottom. My iOS development signing identity showed up and I was back in business.
Removing distribution profiles from device in Organizer solved this issue for me
1.Run the Application using development certificates in both debug and release area in code signing identity.
or
2.Use the development certificate in debug area and distribution certificate in release area.

Resources