Author Archives:

T3P #1 Setting up for IPhone Dev

 

The Tale of 3 Platforms Series (T3P) is the story of creating the same application NATIVELY on each platform IPhone, Windows Phone, and Android. (If you are looking to use phone gap for cross platform, check out my other series Phone Gap Tutorials) As we build the application we will talk about tips, tricks, and try to get the app to work on each platform the same way.

The first thing i had to do was go out a buy myself a Mac.  Something that was good enough to do dev on without breaking the bank.  I found a great deal at Best Buy (open box AND Rebate) for a MacBoo Air.  Installed Bootcamp (And Windows 7) and we were on our way.

NewImage

On a side note before we begin, I will say that it has been interesting to get back up to speed on a Mac. I have owned them in the past, but when you need to actually do things on one (besides email and web) it can be a real time drag to get comfortable.  For example, I needed a blog post editor like Live Writer, (since I am doing this post from the Mac). It turns out that Live Writer is the MAN (or errrr ummm the Writer).  I am using MarsEdit right now but can’t see spending the $40 it costs when my trial is over when it is so weak compared to Live Writer. There are a couple that are supposed to be better but they don’t work on Lion.   Another thing that took me a while is Screen Capture.  I figured out how to finally do it on a Mac : Ctrl +Cmnd+4+tab+stand on your head,  but it only allowed me to copy to clipboard or to desktop, no edit.  As you can see above, sometimes you need to blot something out.  Anyway, after some searching, I found a program called Skitch that is free and seems to do the job.   So I think that I have now realized that I am going to be dealing with a few non-dev issues before I can really get a nice dev flow going.

In addition to the above… I came to realize that I did not have enough room to do bootcamp on this machine.  This was the first thing that was really easy to fix (Thanks to my buddy Scott Cate) I just had to go to Finder and open up the bootcamp assistant and then three steps later, the mac had reclaimed the space.

 

OK… Back to our IPhone Setup.

The first thing I did was to sign up as a developer at apple. https://developer.apple.com/ .  This cost $99 dollars and took a few emails and about a day or so before I was “part” of the developer program.  On the developer site, there are Getting Started Videos and Getting Started Documents.  The videos seemed to be for development topics like “implementing in app purchases” or “Game Center Essentials”. So I went to the “Getting Started Documents” section. There I found the “Start Developing IOS apps today” document.  This looked like the right place.

Start Developing with IOS

 

The first page stated :

As you proceed through the road map, you will use Xcode and the iOS SDK, Apple’s tools for app development. You will learn the basics of programming with Objective-C, the language that powers all iOS apps and frameworks, and will explore the Cocoa Touch frameworks. You will create a simple iOS app and learn how to test it on a device. Finally, you will learn how to submit an app to the App Store.

 

Seems easy enough…

So first I went to the App Store to Download XCode

NewImage

 

But when I tried to install it, it said Sorry Charlie.

NewImage

 

As you can see above… I have 10.7.2.  So I need to update the mac os.

 

OK… Mac updated to 10.7.3 now… I went back to the App Store to Install Xcode and now it lets me install.

 

NewImage

 

Once this is complete, there is a Developer Folder on my Desktop with all the tools I need for development (I think) :) .

In the next post we will start with a simple Hello World app before we move on to Android.

Other Posts in this Series

(This list will automatically grow as I write them)

 

 


Related Posts:

  • No Related Posts


Can your phone do Mach 5

Now I admit, this is a really cheezy video… but it does go to show you the quality workmanship of the Nokia phones…. So I ask you, can YOUR phone do Mach 5?

Related Posts:



Phone Gap Tutorial #3 – Reducing the load


This is a   tutorial Series in which I will create a phone gap application for each of the platforms it supports. It is mostly a journey of my own that you get to follow along on.  I will start with Windows Phone and then convert it to IPhone, IPad, Android, Blackberry, Symbian. We will discuss tips and tricks along the way.

In the last post Phone Gap Tutorial #2 we looked at everything that was created for us when you start a project for Windows Phone from scratch. As I said in that post :

The first folder you will notice is the GapLib folder. This contains the Phone Gap dll that is specific to windows phone. This .dll has some interesting side effects when it comes to submitting to the marketplace.

In this post, we will discuss those issues and show you want you need to do to get around them.

If we look at the Solution Explorer we can see that there is a folder with the WP7GapClassLib.dll which is all the code of . We can also see that there is a reference to it as well.

image

Normally, this would be fine but with Windows Phone and the Windows Phone marketplace, the source code from phone camp contains information on ALL the capabilities.  (Since this is what does, it connects your HTML to the native capabilities). Normally this would be great, but since during the Marketplace verification process it will detect capabilities and list them to the users who will download your application, we don’t want that.

Why don’t you want that?   Well, its simple, if you are writing an app that DOES NOT use contacts, or the phone dialer, or the camera, etc… you don’t want the marketplace to say you do because some users may stay away from your application because you pull to much of their data.

So how do you fix this?  Its easy.   First we remove the reference to WP7GapClassLib (Right click –> Remove), and delete the GabLib Folder

 

image

Next we want to add another project to this solutions.  (Right click on Solution in Solution Explorer –> Add Existing Project) and navigate to where you downloaded in the \lib\windows\framework folder.

image

You will notice that there are 2 projects in here

  • WP7GapClassLib.csproj (This is the one with the FULL Source- we DON’T want this (see above))
  • WP7GapClassLibBare.csproj (This contains the bare minimum for ))  SELECT THIS ONE

 

Then add a reference to this project from your project (Right click on references –> Add Reference –> Projects Tab)

image

If you build and run the project, everything should run fine. BUT at this point you don’t have access to any of the capabilities of the native phone from you HTML.

To show you this simply, we will try to use the camera from our HTML 5 (Example borrowed from )

First add a call to getPicture to the onDeviceReady() method.

 

navigator.camera.getPicture(onSuccess, onFail, { quality: 50 }); 
 

Next, add the onSuccess and onFail methods we pointed to in the getPicture method.

function onSuccess(imageData) {
            var image = document.getElementById('myImage');
            image.src = "data:image/jpeg;base64," + imageData;
        }
        function onFail(message) {
            navigator.notification.alert('Failed because: ' + message);
         }

 

Next, in the same document (in the body section), we will add a link that will call the showAlert() function.  

If you try to run this project now, it wont work. And if you look in your Output window, it will show the following.

image

And you should also get an alert in the emulator (from the onFail function)

image

That is because since we are only using the WP7ClassLibBare project, we need to add this functionality in if we want to use it. (This is what we want, add ONLY the capabilities that we need)

Right click on the Plugins Folder and select Add Existing Item.

Navigate to where you donwloaded phonegap and go to the \lib\windows\framework\PhoneGap\Commands folder.

 

image

Select camera and choose Add As Link.

Now run the code and you will see you have access to the camera. 

Now since we are not using the camera in this application right now, we are not doing anything special with this code. This was just to show you what you will need to do going forward to add functionality to your phonegap application as you build it.

In the next tutorial, we will begin to build the pages in our application and talk about making it METRO.

Other Posts in this Series

(This list will automatically grow as I write them)


Related Posts:



Windows Phone Database Tutorial

[image2.png]When creating applications for the Windows Phone, there is one basic thing that almost ALL applications need to do, Save Data. If its more than just small bits of data you will probably want to store it in a database. In Windows Phone, this can be done easily, but in different ways.  One of the people on my team Jerry Nixon who is a developer evangelist on my team wrote a great series on this.  The first one is using the Code First approach.

Storing Windows Phone application data is a pretty normal requirement. If you want it to persist across sessions, or even phone reboots, you really have three options:

  1. Save to the Cloud
  2. Save to Isolated Storage
  3. Save to Local Database

Each is correct for certain scenarios. But in this article, I will ONLY walk through the Local Database. This is an enhanced version of SQL CE – meaning your SQL skills are an asset. And, if you don’t have them, they …

Read the whole article  HERE

Related Posts:



Add Facebook Login to Your WP7 App

imageHaving a single sign-on is cool for you application. In this day an age, it is enough to try to remember even 10 of your passwords.  Outlook/Exchange, LiveID, Facebook, etc…  If I had to remember a password for every website and app I have, it would drive me crazy. Good thing that we have claims based identity.  Now I just need to remember my LiveID of Facebook Sign on (Among others).  Now if you are creating a WP7 application and want to take advantage of that, you can take advantage of a nuget package that takes the hard work out of it for you.  My buddy Bruno Terkaly has created step by step instructions on how to add this to your windows phone application.

Read More Here

Related Posts:



Phone Gap Tutorial #2–Looking Around


This is a   tutorial Series in which I will create a phone gap application for each of the platforms it supports. It is mostly a journey of my own that you get to follow along on.  I will start with Windows Phone and then convert it to IPhone, IPad, Android, Blackberry, Symbian. We will discuss tips and tricks along the way.

In the last post Phone Gap Tutorial #1 we looked at how to get ready to use and we created a sample project.  In this next tutorial, we are going to look at the files that were created and the differences between this and a standard windows application.

If you look at the files in the solution explorer, you will see some folders and files that are not part of the normal Windows Phone Application.We will only touch on items that differ from a normal application.

image

The first folder you will notice is the GapLib folder. This contains the dll that is specific to windows phone.  This .dll has some interesting side effects when it comes to submitting to the marketplace.  We will cover this in the next post. 

The next folder is the plugins folder. This is empty for now but you can use this to make writing applications even faster.  There are a few plugins already created for the windows phone including :

  • Child Browser
  • Facebook
  • Live Tiles
  • PGMapLauncher
  • PGSocialShare

We will also discuss these further in a future post. If you want to learn more on how to create plugins you can go to the wiki here : http://wiki.phonegap.com/w/page/36752779/PhoneGap%20Plugins  or if you just want to use the current plugins you can go here : https://github.com/purplecabbage/phonegap-plugins/tree/master/WindowsPhone

The next folder (www)  is where the “Guts” of your application will go. Right now it has an index.html file, a css page and the phonegap js file.

If we peek at the index.html file we can see a simple HTML file which adds and event listener for Device ready. deviceready is an event that fires when PhoneGap is fully loaded.

The code then adds some text to the innerHTML of the welcomeMsg
(<div id=”welcomeMsg”>{It inserts it here}<div>

and then writes to the VS output window. This is useful to know for helping you debug later.

<script type="text/javascript">

        document.addEventListener("deviceready",onDeviceReady,false);

        // once the device ready event fires, you can safely do your thing! -jm
        function onDeviceReady()
        {
            document.getElementById("welcomeMsg").innerHTML += "PhoneGap is ready! version=" + window.device.phonegap;
            console.log("onDeviceReady. You should see this message in Visual Studio's output window.");

        }

      </script>

The phonegap-(insert version here).js file has some helpful comments about the order of events including the deviceready event.

/**
 * The order of events during page load and PhoneGap startup is as follows:
 *
 * onDOMContentLoaded         Internal event that is received when the web page is loaded and parsed.
 * window.onload              Body onload event.
 * onNativeReady              Internal event that indicates the PhoneGap native side is ready.
 * onPhoneGapInit             Internal event that kicks off creation of all PhoneGap JavaScript objects (runs constructors).
 * onPhoneGapReady            Internal event fired when all PhoneGap JavaScript objects have been created
 * onPhoneGapInfoReady        Internal event fired when device properties are available
 * onDeviceReady              User event fired to indicate that PhoneGap is ready
 * onResume                   User event fired to indicate a start/resume lifecycle event
 * onPause                    User event fired to indicate a pause lifecycle event
 * onDestroy                  Internal event fired when app is being destroyed (User should use window.onunload event, not this one).
 *
 * The only PhoneGap events that user code should register for are:
 *      onDeviceReady
 *      onResume
 *
 * Listeners can be registered as:
 *      document.addEventListener("deviceready", myDeviceReadyListener, false);
 *      document.addEventListener("resume", myResumeListener, false);
 *      document.addEventListener("pause", myPauseListener, false);
 */

As for the rest of the phonegap-(insert version here).js file, we will try to dip into here as we continue to build the application.

The GapSourceDictionary.xml file lists all of the HTML application resources for this project. At the application start, this XML file is read, and each file is added to isolated storage so that it can be served by the WebBrowser control. (If you have not built your project yet, you this will be blank) This is preformed by the ManifestProcessor.js file.

<GapSourceDictionary>
    <FilePath Value="www\index.html"/>
    <FilePath Value="www\master.css"/>
    <FilePath Value="www\phonegap-1.4.1.js"/>
</GapSourceDictionary>

 

The last piece that is PhoneGap specific is in the MainPage.xaml.  In there you will find the PGView control.  This is a control that is found in the WP7GabClassLib.dll. 

<my:PGView HorizontalAlignment="Stretch"
                   Margin="0,0,0,0"
                   Name="PGView"
                   VerticalAlignment="Stretch" />

If you wanted to see what this control is made of, you could look at it in the files you downloaded in this folder callback-phonegap-1.4.1-0-g0d1f305\callback-phonegap-0d1f305\lib\windows\framework

As you can see, it’s a modified WebBrowser control.

        <phone:WebBrowser x:Name="GapBrowser"
                          HorizontalAlignment="Stretch"
                          VerticalAlignment="Stretch"
                          IsScriptEnabled="True"
                          Foreground="White"
                          Navigated="GapBrowser_Navigated"
                          Loaded="GapBrowser_Loaded"
                          Unloaded="GapBrowser_Unloaded"
                          ScriptNotify="GapBrowser_ScriptNotify"
                          LoadCompleted="GapBrowser_LoadCompleted"
                          Navigating="GapBrowser_Navigating"
                          NavigationFailed="GapBrowser_NavigationFailed"
                          IsGeolocationEnabled="True" />

 

That’s it for this post. Now you know what is created for you when you start a new project.

In the next tutorial, we will look into how we need to modify our project to address the windows phone marketplace. (Trust me, we need to address it first)  Smile

Other Posts in this Series

(This list will automatically grow as I write them)


Related Posts:



New Facebook App for Windows Phone

clip_image001I have been using the Facebook features of my Windows Phone for a while now but mostly through the People Tile and NOT the Facebook app. Thankfully now there is a new and improved Facebook Application.

Download it and let me know what you think.

The marketplace link   http://www.windowsphone.com/en-US/apps/82a23635-5bd9-df11-a844-00237de2db9e

Their facebook page : http://www.facebook.com/apps/application.php?id=135892916448833

Engadgets post on it  : http://www.engadget.com/2012/02/14/facebook-app-windows-phone-update/

Related Posts:



Phone Gap Tutorial #1- Getting Started


This is a   tutorial Series in which I will create a phone gap application for each of the platforms it supports. It is mostly a journey of my own that you get to follow along on.  I will start with Windows Phone and then convert it to IPhone, IPad, Android, Blackberry, Symbian. We will discuss tips and tricks along the way.

In this post, we will look at what you need to do to get started using using Windows Phone.  The first thing you need to do is download the tools.

Go to http://phonegap.com and click on the Download PhoneGap button. It is currently at version 1.41image

The file will be called callback-phonegap-1.4.1-0-g0d1f305.zip (of course the number will change as new updates are applied).  It is called callback-phonegap because…. now take a breath here…. Nitobi, the company that create (at a hackathon… cool), was acquired by  Adobe who then jointly with Nitobi donated the project to the Apache Software Foundation (ASW).  This is a good thing since Adobe will continue to back the project while allowing others to continue to contribute. Now why is it called Callback you ask?  Well, the name inside ASW for is Callback….. or at least it was, it has since been changed to Apache Cordova, so I assume the file name will change soon to.

So once you have downloaded and unziped the file, you will want to navigate to \callback-phonegap-1.4.1-0-g0d1f305\callback-phonegap-0d1f305\lib\windows.  You will see many things in here, but we are only concerned with one right now. PhoneGapStarter.zip (We will talk about PhoneGapCustom.zip later).  We want to copy this to our Visual Studio Templates folder so we can create projects in Visual Studio. 

Copy the PhoneGapStarter.zip file to C:\Users\[USERNAME]\Documents\Visual Studio 2010\Templates\ProjectTemplates\Silverlight for Windows Phone

Now open up Visual Studio (This works with the full or express version) and go to File –> New Project

Select Visual C# –> Silverlight for Windows Phone

You should see a project template for PhoneGapStarter

image

Name Your project and hit OK.  That will create your project.

In the next tutorial, we will walk through all off the files and the set up of your New Phonegap project.

Other Posts in this Series

(This list will automatically grow as I write them)



Related Posts:



WP7 Rest … The Easy Way

Over and over again, I see developers that have this great idea for an application that pulls cool data from a  great services BUT get tied up in the implementation of “Getting It Done”.  So I thought I would show you a quick and easy way to get REST data from a service, transfer the JSON data to a POCO list and Bind it to a listbox.  (In under 3 minutes)

On your Mark

Get Set

Go.

The first think you need to do is find some Data that is interesting to you.  For me, I LOVE coffee so I want to create an application that shows me all the coffee places that are near to me.  I can do this using Bing Search  http://msdn.microsoft.com/en-us/library/dd251014.aspx 

Specifically, I am going to use the PhoneBook Request part of the API that is like a Yellow Pages API.  It will give me all the business that designate themselves as “Coffee” places.

(Yes I know I am not using MVVM)

The first thing I do is Create a method called GetData() and call it from my MainPage() Constructor

  public MainPage()
        {
            InitializeComponent();
            GetData();
        }

        private void GetData()
        {
            string uri = "http://api.bing.net/json.aspx?AppId=YOUR_APP_ID&Version=2.0&Market=en-US&Query=Coffee&Sources=phonebook&latitude=33.8563&longitude=-118.1232";
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(uri));
            request.BeginGetResponse(new AsyncCallback(ReadCallback), request);

        }

In GetData() the first thing I do is make a call to the BING  API. 

The first part of the call shows that I want json returned and supplies my App_ID (Removed from post)  ( You can get your own Bing API key here http://msdn.microsoft.com/en-us/library/dd251020.aspx )

http://api.bing.net/json.aspx?AppId=YOUR_APP_ID

Next I set the version, Market, and what I am looking for

&Version=2.0&Market=en-US&Query=Coffee&

And finally, I tell it I am looking at the phonebook part of the API and where I want to search… In this example I am hardcoding the lat/long but you would of course use the Geo Location from the phone, but I wanted to keep this simple.

Sources=phonebook&latitude=33.8563&longitude=-118.1232";

Next, We then need to make the call to the service.  We will use a HttpWebRequest by passing it the URI we just created

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(uri));

And then making in the call and supplying it the CallBack method (Where the call returns to when it is finished)

request.BeginGetResponse(new AsyncCallback(ReadCallback), request);

Now here is the fun part. To work with the JSon data the is returned from this query, we need to create the class structure that represents the data…….. ugggggg what a pain right?   Nope Wrong, All we need to do is use http://json2csharp.com/    Just paste in either the JSon returned OR the URI String, and it will create the classes for you. So when I paste in my URI String above, it gives me the following.

(you can, of course, break up these classes into separate files but for now, I just pasted them at the bottom of the MainPage.xaml.cs file.)

 

public class Query
    {
        public string SearchTerms { get; set; }
    }

    public class Result
    {
        public string Title { get; set; }
        public string Url { get; set; }
        public string Business { get; set; }
        public string PhoneNumber { get; set; }
        public string Address { get; set; }
        public string City { get; set; }
        public string StateOrProvince { get; set; }
        public string CountryOrRegion { get; set; }
        public string PostalCode { get; set; }
        public double Latitude { get; set; }
        public double Longitude { get; set; }
        public string UniqueId { get; set; }
        public string DisplayUrl { get; set; }
    }

    public class Phonebook
    {
        public int Total { get; set; }
        public int Offset { get; set; }
        public string LocalSerpUrl { get; set; }
        public string Title { get; set; }
        public List<Restuarnt> Results { get; set; }
    }

    public class SearchResponse
    {
        public string Version { get; set; }
        public Query Query { get; set; }
        public Phonebook Phonebook { get; set; }
    }

    public class RootObject
    {
        public SearchResponse SearchResponse { get; set; }
    }

Now that you have the classes that hold the json that is returned, all you need to do is create the ReadCallback Method (Defined above)

private void ReadCallback(IAsyncResult asynchronousResult)
        {
            HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
            HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
            using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream()))
            {
                string resultString = streamReader1.ReadToEnd();
                var ser = new DataContractJsonSerializer(typeof(RootObject));

                var stream = new MemoryStream(Encoding.Unicode.GetBytes(resultString));
                DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(RootObject));
                RootObject myBook = (RootObject)jsonSerializer.ReadObject(stream);

                Deployment.Current.Dispatcher.BeginInvoke(() => coffeeShops.ItemsSource = myBook.SearchResponse.Phonebook.Results); 

            }
        }

You can see that we use a stream reader to read the results and then use a DataContractJsonSerializer to add the data to the RootObject (Root Object is one of the classes that were created for us that encapsulates all the others)

On the last line, I marshall the data to the UI thread using Dispatcher.BeginInvoke and bind it to a ListBox called coffeeShops.

That’s IT….

Now it took me 30 minutes to write this up, but it should take you only 3 minutes to implement.

Enjoy Smile

Related Posts:



Virtualization for Developers

One of the Evangelists on my team from the IT pro side of the world ( Chris Avis ), has put together a series of blog posts around Virtualization. Virtualization is here to stay. It doesn’t matter if you are an IT Professional for a multinational company, or running a small business, chances are, virtualization is making an impact on how you work. Developers are also leveraging virtualization to gain efficiencies, stabilize their test environments and more.

The series has a strong focus on delivering the skills required to take and pass the Microsoft Windows Server 2008 R2, Server Virtualization Exam (70-659). But even if you aren’t interested in taking the exam, the information provided is invaluable to anyone that is just starting to use the Microsoft Virtualization platform. There is also some deep dive technical information planned for those that already work with virtualization.

Check out the blog series at his blog!

Passing the Windows Server 2008 R2, Server Virtualization Exam (70-659) – Part 1 – Study Resources

Passing the Windows Server 2008 R2, Server Virtualization Exam (70-659) – Part 2 – Skills Measured

Passing the Windows Server 2008 R2, Server Virtualization Exam (70-659) – Part 3 – Installing and Configuring Host and Parent Settings

Passing the Windows Server 2008 R2, Server Virtualization Exam (70-659) – Part 4 – Creating and Configuring Guest VM’s

Passing the Windows Server 2008 R2, Server Virtualization Exam (70-659) – Part 5 – I’m a Developer! Why Virtualize?

Related Posts:

  • No Related Posts