Xamarin.mac App Open At Login
Xamarin gave the app access to all required data, such as the user’s location, media files, camera, and Wi-Fi connection information. By tightly integrating the app into the platform with Xamarin, they managed to create an intuitive user experience, regardless of whether a person speaks English, and support uniform processes among the staff. Anatomy of a Xamarin.Mac App NSDocument version Applicaon Delegate Called with applica0on events, among them “FinishedLaunching” Info.plist Applica0on metadata, used by the OS (app name, requirements, doc type handlers, etc) Main applicaon menu Interface defini0on for your main menu Main Window UI Definion UI for your Main Window, edited. This is a nice and simple app that is ideal to use to get started. Begin with the user interface. You will want a way of displaying the current count and a button that makes the count increase. Open the Main.XAML file in the Counter project folder. This is the default UI file the Visual Studio tooling creates from the New Project template. Xamarin.iOS & Xamarin.Mac Welcome! This module is the main repository for both Xamarin.iOS and Xamarin.Mac. These SDKs allow us to create native iOS, tvOS, watchOS and macOS applications using the same UI controls we would in Objective-C and Xcode, except with the flexibility and elegance of a modern language (C#), the power of the.NET Base Class Library (BCL), and two first-class IDEs. Using Xamarin.Mac in order to mix Xamarin.ac with Xamarin.Android and Xamarin.iOS, mobile app developers can share up to 90% of the original code on iOS, Android, and Mac OS. In addition to this, Xamarin.Mac is integrated with Xcode, so a mobile app developer can use Xcode's interface builder to build the user interface of the app. Run the app, minimize it, then tap on a deep link, e.g. From an event in the Calendar app. Expected Behavior. The Xamarin iOS app will launch and one of the overridden methods will be called. Actual Behavior. The Xamarin iOS app launches (so the deep link registration is working) but the overridden methods are not called.

I have an app, called Voice in a Can, which lets you use Alexa on your Apple Watch and iPhone. I’m working on bringing it to the Mac, and one of the things I want is that it be started at login, if the user wants this.
Stockfolio free mac app. To do this in a sandboxed app, you need to create a helper app, and bundle it inside your main app, in a specific location (/Contents/Library/LoginItems). This helper app is automatically launched at startup, and has no UI - all it does is launch the main app, which in my case sits as an icon in the system toolbar.
There is a great blog post on how to do this by Artur Shamsutdinov, which this post is based on. This blog post adds some detail, information on how to use MSBuild, and trouble-shooting information. You really should check out Artur’s post too.
I created a main application, in my case it is called VoiceInACan.AppleMac:
I made sure this was signed, and configured to use the SandBox.
In my AppDelegate I called SMLoginItemSetEnabled to tell MacOS to launch my helper app at startup (the com.atadore.VoiceInACanForMacLoginHelper is the bundle ID of my helper app, defined below) :
In a real app you’ll not want to auto-launch a Sandboxed app without permission from the user since your app will be rejected by App Review when you submit it.
I created a helper Mac app, as another project, in my case called VoiceInACan.AppleMacLoginHelper
I made sure this was signed, and configured to use the SandBox
I edited the storyboard to uncheck Is Initial Controller (in the properties on the right) to ensure the helper app has no UI:
I updated Info.plist to indicate the app was background only (because it will have no UI and serve purely to launch my main app on startup):
I added a dependency from my main app to the helper app by right-clicking on References in my main app, selecting Edit References, going to the Projects tab and checking the checkbox next to my helper app:This ensures that the helper app is built before my main app.
In my AppDelegate.cs in my helper app, I launch my main app:
I updated my main app to embed the helper app within it
So far I’ve created two apps: the main app, which provides my main functionality (in my case Alexa), and a helper app which has no functionality other than to launch the main app. In order for the SMLoginItemSetEnabled to work the helper app needs to be embeded within the main app.
To do this, I edited the csproj of my main app, and added markup to embed the main app. Here are the bits, the complete thing is below:
First, define an ItemGroup that references all the files in the helper app’s bundle (the Configuration refers to Debug or Release):
Next, copy those files into the right place in the main app (note that this is done after _CopyContentToBundle so that it is copied before the build signs the final bundle):
Finally, the embeded bundle’s files can be signed (this may not be necessary … first try without this):
This is my complete modification to my csproj (after the import of the Xamarin.Forms.targets):
Finally copy your main app’s bundle to the Application folder, and run it so that it registers the embedded helper to start on login.
Troubleshooting SMLoginItemSetEnabled
The first challenge is getting log information. If you run the Console app, it only shows you information from after it was launched, which is after you login. You can get historical information, from the terminal
This will show you the last day’s worth of logs. You’ll want to look for messages from otherbsd
The second challenge I faced was that although I registered the startup item properly, it wasn’t being launched properly. I was getting this cryptic error Could not submit LoginItem job com.atadore.VoiceInACanForMacLoginHelper: 119: Service is disabled:
After Googling, I discovered the lsregister command, and was able to see many many “registrations” of my helper app, from developing and backups etc
What fixed it for me, and your millage may vary, and you should really check what these commands do before executing them, was:
I then re-ran my main app, which re-registered my helper app as a single entry in lsregister and joy, my app launches at startup. I started working on this yesterday at 7:30 am and got it working around 1:30 pm. I’m hoping if you need to do something similar this post will shave a little time off your experience!
Acknowledgements
There is no way I’d have got this working without Artur Shamsutdinov’s blog post from 2016.
- Xamarin Tutorial
Xamarin Forms Mac App
- Xamarin Useful Resources

- Selected Reading
In this chapter, we will see how to create a small Android application using Xamarin.
Hello Xamarin! Application
First of all, start a new instance of Visual Studio and go to File → New → Project.
On the Menu dialog box that appears, go to Templates → Visual C# → Android → Blank App (Android).
Give an appropriate name for your application. In our case, we name it “helloWorld” and save it in the default location provided. Next, click the OK button for the new “helloXamarin” project to load.
On the solution, open Resources → layout → Main.axml file. Switch from Design View and go to the Source file and type the following lines of code to build your app.
In the above code, we have created a new Android textview. Next, open the folder values and double-click Strings.xml to open it. Here, we are going to store information and values about the button created above.
Open MainActivity.cs file and replace the existing code with the following lines of code.
Save the application. Build and then run it to display the created app in an Android Emulator.
If you do not have an Android Emulator, then follow the steps given in the next section to create one.
Setting Up an Android Emulator
On your Visual Studio menu, go to Tools → Android → Android Emulator Manager. On the pop-up window that appears, click the Create button. It will display the following screen.
Open Source Xamarin Apps
On the above screen, supply the AVD name you want. Select a device that is appropriate for your display, e.g., Nexus 4” display. Select your target platform. It is always advisable to test on a minimum target platform, e.g., API 10 Android 2.3 (Gingerbread) so as to ensure your App works across all Android platforms.
Fill in the rest of the fields and click the OK button. Your emulator is now ready. You can select it from the list of existing Android Virtual Devices and then click Start to launch it.
Modifying HelloXamarin App
Xamarin Mac Textshouldendediting
In this section, we will modify our project and create a button which will display text upon click. Open main.axml and switch to source view. After our textview that we created, we will add a button as shown below.
Xamarin.mac App Open At Login Page
After adding a button, our full code will look like this −
Next, we register our button values in the strings.xml file.
After adding our button in the strings.xml file, we will open MainActivity.cs file to add an action for our button when it is clicked, as shown in the following code.
Next, build and run your application.
Xamarin.mac App Open At Login Yahoo
After clicking on the button, you will get the following output −