XCode 7 : Adding a new device to an XCode-managed provisioning profile

Let me just start this post with a question : why is this still so hard?? Moreover, WHY does it only keep getting harder???

I don’t know what the XCode team are thinking, but the whole point of having your provisioning profiles managed by XCode is that it should make things simple and automagic. Well, not so.

Previous versions of XCode all had their quirks, but at least there was a refresh button that you could press that would reload and regenerate any provisioning profile if you, for instance, added a new device on the member center. Yes, a refresh button. easy right? Well, maybe they thought that was too easy so they decided to remove it.

As of XCode 7, supposedly, all profiles update automatically. Or do they?

I just added a new device to my member center, but it didn’t get added to my XCode-managed profiles. I restarted XCode and nothing. Then I stumbled upon a tip to actually delete the provisioning profiles then wait for XCode to regenerate them again and hit Dowload All. So I went to try to delete them, and guess what, as of the latest update XCode 7.0.1 (7A1001) the option to delete them is gone now. So you can try to right-click on them to your heart’s content and nothing will happen. sigh….I would scream if only it wasn’t so late at night already.

There is a solution, though I don’t consider it a solution at all, more like a brute force workaround:

Deploy a test app from XCode to your new device!

This will trigger XCode to then prompt you about the fact that there is no provisioning profile for that device installed and give you the “Fix Issue” button.

Click on “Fix Issue” and wait till the test app is deployed. I impatiently shortcut it right after clicking it and it still didn’t work, so all good things come to those who wait.

I can’t wait for XCode 8 now to see what is the next dumb thing the XCode team is going to do about this.

Sort it out already, Apple!

 

Implementing a Cross-Platform PDF Viewer in Xamarin.Forms and Android

In this post I’m going to show you how to implement a cross-platform PDF viewer using Xamarin.Forms. We are going to focus on  Android in this tutorial.

The approach we are going to take is to create a Dependency Service implementation on the Android project which triggers a choice for a external PDF viewing app on the user’s phone.

If you are wondering why not just use an embedded WebView to display PDFs, the short answer is that while it would work on IOS this wouldn’t work on any Android versions prior to Lollipop. Also, from a technical strategy and commercial point it may be more beneficial to allow the users freedom of choice. For more on that, you can read my previous blog post WebView Or External Web Picker? Or, When To Give Users Freedom .

Step 1 – Create the Dependency Service contract

On the PCL or SAP project Xamarin.Forms project, create the following interface:

public interface IPdfViewer
{
  void View(string filePath);
}

Step 2 – Create the Android implementation

On your Android project, create the following class:

public class PdfViewer : IPdfViewer
    {
        public void View(string filePath)
        {
            //copy to global
           
            var localFileStore = new LocalFileStore();
            localFileStore.CopyToGlobalStorage(filePath);
 
            Android.Net.Uri uri = Android.Net.Uri.Parse("file:///" + localFileStore.GetGlobalPath(filePath));
            Intent intent = new Intent(Intent.ActionView);
            intent.SetDataAndType(uri, "application/pdf");
            intent.SetFlags(ActivityFlags.ClearWhenTaskReset | ActivityFlags.NewTask);
 
            try
            {
                Xamarin.Forms.Forms.Context.StartActivity(intent);
            }
            catch (Exception)
            {
                Toast.MakeText(Xamarin.Forms.Forms.Context, "No Application Available to View PDF", ToastLength.Short).Show();
            }
        }
    }

Xamarin build error : No valid iPhone code signing keys found in keychain

if getting the error “No valid iPhone code signing keys found in keychain” when building your Xamarin IOS project, check that you are building against an ios simulator.

Visual Studio defaults to Device as a build target when creating a new project so this could be what is causing your error.

visual studio set to Device build target

Change to a simulator instead and try again.

Build target set to a simulator

If you do intend to deploy to a Device though, then the error is telling you that you haven’t set up a Device properly.

In order to do that you have to sign up to the Apple developer programme and follow the instructions.