Xamarin UIDeviceFamily

I was releasing an app to the the Apple App store tonight (actually two apps, go me! i've done an Atley Hunter ;-) )

One of my apps encountered a problem when I tried to upload my archive

 

"This bundle is invalid. The UIDeviceFamily key must be present when requiring a MinimumOSVersion of a t least 3.2."

This did confuse me for a while, I did a bit of research and this this supposed to be set automatically with XCode when I set the target platform. 

Given I was using Xamarin Studio I was a little unsure where I stood so i took a shot in the dark. I changed the platform in Xamarin to Universal and then back to iPhone/iPod problem solved,

hope this tip helps someone 

 

 

To Xammer or not to Xammer

Xamarin vs XCode

Anyone that reads this blog regularly or knows me, will know that I’m a C#/Java programmer primarily (ok I think I’ve just come out, this is the first time I’ve ever called myself a Java programmer), but I love all other languages, especially javascript and objective-c, lets put it out there, my objective-c is poor to middling at best, mainly because I’ve only written 3 iOS applications. I was in London this week and I got an early preview of a new service, it looked pretty good (awesome even) so I was thinking of how I could write a few of my own clients for this. I’m a bit greedy in that I want to do everything myself which is pretty much impossible given all my other commitments.

Client options

  • Html5 Desktop Client
  • iOS native client
  • Droid native client (I’ve never strictly speaking done one, unless you include my hello world post two years back)
  • PhoneGap/KendoUi iPad/Droid apps (I’m doing the phone apps for my Expenses service with these technologies).

Decisions tree

My first instinct was to go the PhoneGap with KendoUI, I actually did the initial layout and had a look in the Android Emulator and it was pretty nice (as I was in London I didn’t have my MacBookAir with me and I didn’t have the Visual Studio Phone Tools installed either so eclipse/android it was with that painfully slow emulator). The problem I encountered with this approach was that CORS was not enabled by default and I use my visual studio to develop design debug (Phonegap can do CORS once the site is white listed).

My next option was to write the native clients, when I arrived back home I quickly ensured I could connect to the server (that uses basic authentication), I used objective-C firstly, I didn’t use any 3rd party libraries and the end result appears a little verbose (a better iOS developer will probably cry when they look at these screenshots and tell me use AFNetworking etc (which I used in my BrianKeating.net companion app).

XCode Version

image

Make the initial request and delegate to the view class.

 

image

Here i set the username and password for the request when/if challenged.

Screen Shot 2013-05-04 at 22.15.41

Here i allocate a place to store the response if it’s was a success and save to data into urlData.

image

Here I list all the key value pairs in the JSON returned (something I  don’t actually show in the c# version.

The advantage of XCode/Objective-C to me is that it’s a different toy to play with, that said c# is just a fantastic language it’s RAD and it Xamarin have done a fantastic job of bringing it to the iOS and Android Platforms.

MonoDevelop Version

This  screen shot shows the same request to the server as done in XCode, the difference is that this took me about 1 minute where the objective-c version took me about 25 (although i did reuse the storyboard).

image

 

 

 

 

You said Decision?

So how will I proceed? I’m going to ditch the objective-C approach for sure:

Reasons:

  • It’s so much faster! I love C++ but can’t get myself to use it for app dev these days simply because C# kicks it to touch for rapid application development.
  • Because I don’t expect to continue this POC myself and will have to hand it over to someone, and I don’t know anyone else on the team that knows objective-C.

I’m actually still leaning towards the PhoneGap/KendoUI option, I just need to get my grubby hands on the server so i can add the CORS headers (again because I don’t want to do the bulk of my debugging with Phone gap but rather IE/Chrome and I quite like my browser stack (jQuery/Knockout/Breeze etc) but the main advantage is that the the same source can then be used for the Android platform. Sure Facebook/LinkedIn etc have all been moving away from html5 because of the tooling, but I feels it’s the best solution for getting to both markets quickly.

So that is my reasoning, I expect everyone with be faced with much the same decisions and will have to weight the pros and cons themselves.

File Upload MCV4 Web API, Knockout.js

 

I wish to follow up on my previous post Uploading a file in MVC4 C#5 .NET 4.5

I promised a few things here, a ajax client, winrt, iOs, Droid, This post addresses the ajax upload.

First some background, I’m working on an expense tracking system at the moment, the core technologies involved in this Single Page Application are:

  • ASP MVC4 WebApi
  • Html5 SPA
  • Knockout.js

A fundamental part of this system is the ability to upload receipts.
 image

When the user browses to an image file, it gets converted to base64 and uploaded via a MVC4 Api controller.

Here are the important parts:

Html

image

First we create an image where we can display either the previously selected image or the newly selected image.
We only display this image if it’s in the javascript model.

Secondly we bind the html5 input file with a knockout binding.

Javascript

Model

image

The important parts are the image and imageType properties, there also exists a computed property that joins these two so it can be displayed in an image tag. The reason i keep these separated is that I can’t post the source as is without further encoding.

Knockout Bindings

In knockout.js you are not limited to the built in bindings like, click and value, you can create your own,
I’ve taken https://github.com/khayrov/khayrov.github.com/blob/master/jsfiddle/knockout-fileapi/ko_file.js as my start point, this pretty much does what I want, however I made a slight tweak in that i wanted base64. (basically because I’ve written some of the objective-C iOS app already and didn’t fancy changing it).

 

image

WebApi

image

ExpenseDto

image

All source can be viewed @ https://github.com/brianbruff/Expenses

ASP MVC4 Web API file upload: Unexpected end of MIME

 

So I’ve had a problem uploading a file using a HTML5 input of type file field.

image

For love nor money could I see a problem with the code above (in my defence I’m working on this project late in the evening and have my First dose of Man Flu this year, I’m a 2012 survivor see: www.manfluanonymous.com )

When i get into my server code an exception was getting thrown when i read the multipart post.

image

All the Googling in the world didn’t help me, I saw lots of people adding “\r\n” which I’m still scratching my head over to be honest, I saw others complain about the MVC4 beta..

 

But hang on: I’ve done this before: So what has changed? actually something really silly ,

I simply forgot to set the input name attribute!!!

image

Hope this helps somebody …

Enabling Facebook OAuth in MVC4 SPA

 

There are two steps, the first step is to register a facebook application, after you register you will have a key and password. The next step will be to insert these into you application.

 

Step 1.

    Enable OAuth login using Facebook, Twitter

    Steps to get keys for Facebook

    • Go to the Facebook developers site (log in if you're not already logged in).
    • Choose the Create New App button, and then follow the prompts to name and create the new application.
    • In the section Select how your app will integrate with Facebook, choose the Website section.
    • Fill in the Site URL field with the URL of your site (for example, http://www.example.com). The Domain field is optional; you can use this to provide authentication for an entire domain (such as example.com).
      Note   If you are running a site on your local computer with a URL like http://localhost:12345 (where the number is a local port number), you can add this value to the Site URL field for testing your site. However, any time the port number of your local site changes, you will need to update the Site URL field of your application.
    • Choose the Save Changes button.
    • Choose the Apps tab again, and then view the start page for your application.
    • Copy the App ID and App Secret values for your application, here is what it looks like, I’ve blurred my app id and secret.
    • image
    • Exit the Facebook developer site
    •  

      Step 2.

      Edit your App_Start/AuthConfig.cs with these new settings

       

      image

      That’s it, you can no log in with facebook, see the placeholder template below.
    image

About the author

Brian Keating is a developer addicted to Microsoft Technologies.

Month List

Tag cloud

RecentComments

Comment RSS