Add ios project to xamarin forms solution with droid project

5.2k views Asked by At

I've got a xamarin forms solution with a pcl and a .Droid project. Now I also want to add ios to the solution. How do I do this. From the add dialog I can select add new project, but it seems to add a lot more....So the solution was first created without the ios checkmark....

btw. I'm using xamarin studio

Best regards

2

There are 2 answers

2
Artur Shamsutdinov On BEST ANSWER
  1. Add new Empty iOS project.
  2. Add Xamarin.Forms Nuget package.
  3. Substitute your AppDelegate class with this one:
[Register ("AppDelegate")]
public class AppDelegate : FormsApplicationDelegate
{
    public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
    {
        Xamarin.Forms.Forms.Init();

        LoadApplication (new App ());

        return base.FinishedLaunching(application, launchOptions);
    }
}
0
Matt Ward On

There is not a Xamarin.Forms project template that will do this out of the box. The Xamarin.Forms project templates are designed to be stand alone and ready to run after being created so they will always create a PCL project or a shared assets project.

Artur's answer, of creating a new empty iOS project, adding Xamarin.Forms NuGet package, then modifying the AppDelegate, is a good approach. Although it is missing:

  1. Add reference from the iOS project to the PCL project.

If you compare that with the iOS project created using the empty project with the one created using the Xamarin.Forms project template they are slightly different. So an alternative to creating a new empty iOS project would be:

  1. Create a new Xamarin.Forms solution with the iOS check box selected.
  2. Copy the iOS project into folder inside your existing solution.
  3. Add the iOS project to your existing solution.
  4. Add a reference from the iOS project to your PCL project.

You could try adding a new Xamarin.Forms project to the existing solution using the New Project dialog without creating it separately. I would be careful doing this it may try to overwriting existing project files. If you have already done this then you should be able to remove the new PCL project it added and also the new UITests project it added. Then add a reference from the iOS project to your PCL project.