Wednesday, January 25, 2012

Using ZoneInfo api in wp7

Over recent months I have found planning convenient times for skype meetings between myself and my business partner (who is on the other side of the world) to be a pain. I have been travelling quite a bit so my timezone is constantly changing. I thought "there really should be an app that helps with this"!  I already have world clock for wp7 but this just tells me what the time is now.  I wanted to be able to work out something along the lines of "at 9am tomorrow here in Estonia what will the time be in Brisbane Australia?". 

After a cursory search of the marketplace I couldn't find an app that did this so decided to build the capability into a unit converter app that  I was working on. 

Having worked with timezones in .net before I thought "this will be dead easy". I dived in and built the ui.  Next step was to populate the UI with all of the world time zones so the user can choose which time zone they want to convert from and which time zone they want to convert to.

Unfortunately I soon realised that this would not be as easy as I thought.  In wp7 the TimeZoneInfo class does not have the getsystemtimezones() method. As mentioned in this post.  I'm not sure why? maybe it is because they are trying to keep the wp7 api as lightweight as possible.
Fortunately after some more searching I found http://zoneinfo.codeplex.com/.  A brilliant little .net api for using the tz database of world timezones.

Unfortunately it can't be used with wp7 out of the box, but after a few small modifications it worked great.

I Just did the following:
  1. Downloaded the source code from http://zoneinfo.codeplex.com/
  2. The library is not accessible via silverlight so I needed to create a new silverlight library and copy the classes from the zoneinfo library into it.
  3. I also had to copy the tz database files into the silverlight library and set their build action to resource.
  4. The loadfile / loadfiles methods in Database.cs had to to be altered so that I could pass the uri's of the tz database files.
  5. Lastly I needed to alter the loadfile method to read the file uri and create a StreamReader object.
That's was it.  Now I can convert timezones in wp7.
    //convert local time to the time in Brisbane / Australia
   Zone theZone = Database.GetZone("Australia/Brisbane");
   DateTime d = theZone.ConvertToLocal(DateTime.Now.ToUniversalTime());

Tuesday, January 24, 2012

WP7 Marketplace Certification Hell

A little Background
In late November / Early December I updated our application Camera Flashlight . The original version was turning on the camera flash (to be used as a flashlight) by causing the camera to continually auto-focus. The problem with this method is that it caused the flash to blink on an off momentarily once the camera had focused.  Not ideal for a flashlight but it's an approach that almost all wp7 flashlight apps seem to use.

Since then I worked out how to keep the flash on via accessing the video recorder which is much more desirable because it results in a constant stream of light without blinking.  It also puts less stress on the phone's camera.


Certification Hell
In early December I submitted this application and 5 days later got a message saying that it had been rejected because the application terminated silently on startup.  I had recently started obfuscating my applications with Eazefuscator and thought that maybe that was the cause.  So I switched to another obfuscation program and resubmitted.  6 days later I got the same message. 

By this time I was at a bit of a loss as to the cause. I always try to build good exception handling into my apps so silent termination should not really possible.  The user should always get redirected to a custom error page.  I had also sent the xap to my business partner Jeremy and he was able to side load and run it on his phone without issue. I'd checked the forums but didn't find anything of much help.  So I decided to send a support ticket asking for more information and also asking if the obfuscation could be the cause. 
The response I got was almost comical.

Hello Jeremy,

Thank you for contacting the Windows Phone App hub Developer Support Team. My name is Gary and I will be assisting you. For questions of a more technical nature, the best resource for information would be the App Hub Community Forums. There you will be able to get responses from not only other developers that have may have similar experiences, but also from internal Microsoft Windows Phone team members, as they respond to developer issues there on a regular basis. I have provided the link, below, for your convenience.

http://forums.create.msdn.com/forums/98.aspx


Thanks,
Gary
Windows Phone App Hub Developer Support 

So for a yearly registration fee of $99 all I get is a generic email saying if you have a technical query check the forums. Thanks alot Gary! After that I tried another 3 times to submit my application with small capability changes to wpmanifest.xml file as well as trying g to submit with no obfuscation.  Everytime I was rejected for the same reason.  By then almost 2 months had passed and I didn't seem any closer to having my update on the marketplace. 

The solution
In fairness to Gary at Microsoft Support I did eventually get a few ideas from the forums which pushed me in the right direction.  The first was that you can do beta testing.  This was one of those marketplace features that I was aware of but had never used and kind of forgot about. I submitted my application to beta test.  24 hours later I was able to download it onto my handset via the marketplace.  Sure enough the application terminated silently on startup.  Finally I was able to repeat the issue.

Next I found a forum post indicating that the capabilities in the manifest file could be the cause of my problem.  Well I had already looked at capabilities and run the capability detection tool.  No issues were obvious there.  However the post got me thinking that I might have misunderstood a few things.  I did a bit of research and it turns out that I had totally got it wrong.  I thought that the capabilities you defined in your wpappmanifest file defined what the apps capabilities would be in the marketplace.  I assumed the detection tool was for detecting what capabilities were requried and making sure you had them in your wpappmanifest file and that you hadn't included any unneccesary ones.  However it turns out that when you upload your app to the marketplace it compeltely overwrites your wpappmanifest.xml file with one based on the capabilities that the marketplace detects. 

It seems that a limitation in the detection process was meaning the camera and audio capabilities were not being detected and so the following required lines were being removed from wpappmanifest.xml file.


<Capability Name="ID_CAP_MICROPHONE" />
 <Capability Name="ID_CAP_ISV_CAMERA" />

*Note. you need the microphone capability when accessing the video camera

So these missing capabilities were the problem.  My next issue was how to trick the market place into detecting them.  By adding the following dummy lines of code to my project I was able to achieve this as was confirmedby the capability detection tool

MainPage.xaml.cs
private VideoBrush videoRecorderBrush;
private CaptureSource captureSource;
private VideoCaptureDevice videoCaptureDevice;

App.xaml.cs
Microsoft.Xna.Framework.Audio.Microphone mic = null;

I submitted the application for a beta test. Downloaded it from the marketplace 24 hours later and it was now running correctly.  Problem solved.

Summary
I felt kind of stupid that I had spent so long on such a small and seemingly obvious problem.  But then I got thinking my misunderstanding of how capabilities worked was fairly reasonable.  I really don't see the point of capabilities being based on those in the wpappmanifest.xml file during development if they are just going to get overwritten on marketplace upload.  To me it would make alot more sense if capabilities detected by the capability detection tool be automatically used by visual studio when developing an application. Of course it might be nice to override this behaviour.  But by default it makes a lot more sense. 

Anyway v1.1 of Camera Flashlight has now been approved by the wp7 marketplace and should be available sometime in the next 24 hours.   I hope this post helps someone as I was pulling my hair out for a while there.

Tuesday, January 17, 2012

Beat My Drum

Here's a very rough clip of me playing a beat on our application beat my drum. As you can see I'm no expert and my timing isn't brilliant but it is possible to keep a beat.   


We created beat my drum in October/November 2011.  After playing around with some of the other drum machines on WP7 I was a little disappointed. Some were absolutely useless and didn't let you play 2 drums at the same time.  Many others were not very responsive.  Some were quite responsive and nice to look at it but these seemed to fall down in the way the drums were layed out. Many of the app developers seemed to think it was a good idea for the GUI to be just like a real drum kit.  However I think this is not a good approach for 2 reasons:

1. Wasted screen real estate. 

The phone screen is small enough withough having to limit your taps to the image of a snare, tom or cymbal.

2. The hi hat is in an awkward position.

Most drummers (except for some jazz drummers) will hold the stick in their right hand and play accross their bodies.  This is fine in real life when you've got a large drum kit in front of you and your holding two 40cm sticks.  However on a phone it's awkward.  You have to either turn the phone around and play everything upside down or you've got to attempt to cross your right hand accross you left hand which is difficult when you're playing on such a small screen.  To me it makes a lot more sense to position the hi hat on the top right hand corner of the phone as it is the timekeeper pad that you'll most likely be hitting frequently with your right hand/finger.

So not being satisified with any of the other apps out there I decided to make my own drum machine.  The main roadblock was getting familiar with the touchpanel in the xna library.  Silverlight does not allow two buttons to be pressed at the same time so the user must use the touchpanel and detect multiple screen hits at the same time.

The main lesson I learnt was it is not possible tocreate a responsive touch application like this by just raising gesture events. It seems to work at first but if you start hitting the screen in multiple places frequently you will notice that atleast 60% of the time your second touch will be ignored.  The solution I used was to set up a timer which executed multiple times a second and poll the raw touchpanel data for screen taps. 

For more info you can read a couple of posts I made in the developer forums about this http://forums.create.msdn.com/forums/p/94206/564280.aspx#564280

Creating this simple application turned out to be a good move for us.   Over the last month Beat My Drum has surpassed Camera Flashlight to become our most profitable app. YAY.


Monday, January 16, 2012

2011 Summary - Why we went with WP7

Well 2011 was an interesting year for Mayhem Software.  We published our first application Rescue Ring on the Windows Phone 7 Marketplace on 7/06/2011 and by the close of the year we had a total of seven applications published and 7436 downloads.  So unfortunately we didn’t make the hundreds of thousands of dollars we were hoping for.  But we learned a lot and it wasn’t a terrible start for two guys who are new at this and have only been spending about 15% of their time on it.




Why WP7
When my business partner and I were discussing which mobile platform to target first Windows Phone 7 was not neccessarily our first choice.  In fact initially we were leaning towards Android. I already had a nexus one and android’s lack of restrictions and fast growing market share seemed like the most attractive choice. However on the other hand the potential for huge profits and the many success stories of developer’s who’d targetted iOS were making it look attractive too.  One which we’d been hearing alot about was Halfbrick (the developer’s of fruit ninja) who are from our hometown Brisbane.  At the time Fruit Ninja had already netted Halfbrick over $20,000,000.

However in the end the thing that turned us off both those platforms was the fact that their marketplaces were already extremely crowded.  At the time iTunes had over 300,000 apps on their markplace and Android was not far behind.  Both marketplaces have now exceeded 500,000 apps. 
Windows Phone 7 was a fresh new platform and the opportunity to get in "relatively" early appealed to us.  So needing a new phone my busisness partner bought himself a shiny new HTC Mozart and we dived in.

Things I like about WP7

  • Ease of development.

    The Windows Phone developer tools are easy to install and if you hav a decent net connection you can be running a hello world app in aprox 15 minutes.  Also having extensive .net development experience meant there was a much smaller learning curve for myself as opposed to developers who are unfamiliar with xaml and c#.
  • Slick and original platform.

    WP7 is a slick and responsive OS with a great overall user experience. It's also totally original unlike iOS and Android which are very similar to each other in terms of GUI and user interactions.  So much so that Steve Jobs "reportedly" felt that Android was a rip off of iOS.  I certainly don't agree with that but the similarities cannot be denied.
  • Uncrowded marketplace.

    Ever have a brilliant and original idea for a new app and then feel like breaking your phone when you search the Android or iTunes marketplace and realise loads of similar apps already exist. This happens less often with WP7.
Things I didn't like about WP7
  • Stupidly slow and inefficient verification process.

     To verifiy you really are a legitimate developer Microsoft use geonames.org, or geowankers as we started calling them.  Our experience with them was not good.  We had registered as a partnership and because of this they decided we had to jump through some rediculous hoops to be verified.  The whole process took approximately 3 months.  They would ask for one thing at a time instead of providing us with a complete list of what they needed.  They didn’t accept the statutory declaration we provided them with was signed by a legitimate solicitor and decided they needed extra time to verify his identity and credentials. Unfortunately this seemed to take forever and everytime we asked them how they were progressing the response was always "we need more time". Eventually we gave up waiting and did a new statutory declaration with a justice for the peace. Worst of all they were at best painfully slow to respond to emails. Often they wouldn't respond at all.  This experience almost made us give up and target another platform. After paying $99 and taking a risk on a new and untested mobile operating system this was not the welcome we were hoping for.
  • $99/year developer license.

    When compared to Android’s $30 one off fee this did seem a bit pricey for a platform which almost no one was making any money off.   Infact the price was initially $129 but eventually they reduced it to $99 and issued us a refund.
  • Lack of marketshare. 

    With only 2-3% smartphone marketshare Windows Phone 7 has less users which means less potential customers for us and therefore lower revenues.
  • API restrictions. 

    Windows Phone 7 is more locked down than any of the other 2 platforms we considered.  We are unable to access parts of the API we needed such as the video camera which was often frustrating and meant some of our application features were just not possible to implement.
  • Application certification process is slow and inflexibile. 

    Everytime you submit an update it has to go through certification with Microsoft. Initially this was about 2 days of waiting but over the last 3 months of 2011 this is usually taking about 5-7 days.  In addition once you've made a submission you cannot stop it.  Last month I detected a major bug in the application Secret Santa only half an hour after I'd submitted it for certification.   I was not able to update the submitted application or even delete it.  When I emailed support they advised "wait until the application completes certification.  If it passes just hide it in the marketplace and then submit an update".  It did pass and I did as they advised.  However I had to wait an unneccesary 6 days for them to certifiy it and then another 5 days for them to certify the update that included my bugfix. This was annoying as being an application which is really only useful around Christmas these 11 days meant I missed out on lots of precious downloads.  In addition as I hid the application in the marketplace as soon as it was new it missed out on showing up in the "new application" list on the marketplace which also meant I lost a lot of downloads.
Despite some of the above points I still think Windows Phone 7 is a great platform.  I love it's slickness and responsiveness. (My wife's LG Optimus 7 really makes my Nexus One seem clunky in comparison).  I love developing in .net and silverlight and it’s great to be able to develop apps which don’t get lost in amongst the hundreds of similar apps that already exist. I’m hoping Nokia will continue to build on the success of the Lumia phones and this will result in more money in the pockets of windows phone 7 developers.