<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Xamarin Developer Blog by David Conlisk</title><link>http://web-garden.co.uk/</link><pubDate>Fri, 01 Dec 2017 10:37:02 GMT</pubDate><generator>umbraco</generator><description>This is my blog about Xamarin, Umbraco, .NET development and general web development-related issues.</description><language>en</language><atom:link href="http://web-garden.co.uk/blog/rss.aspx" rel="self" type="application/rss+xml" /><item><title>Alexa integration for the Guide system</title><link>http://web-garden.co.uk//blog/2017/12/1/alexa-integration-for-the-guide-system</link><pubDate>Fri, 01 Dec 2017 10:37:02 GMT</pubDate><guid>http://web-garden.co.uk//blog/2017/12/1/alexa-integration-for-the-guide-system</guid><description>Certified Umbraco Developer | David Conlisk | Web Garden | blog entry</description><content:encoded><![CDATA[ 
<p><a href="https://guide-research.com/" target="_blank"
title="Guide Research"><img src="/media/26442/guide logo.svg" alt="Guide Logo"/></a></p>

<p>If I haven't mentioned it to you before, <a
href="https://guide-research.com/" target="_blank"
title="Guide Research">the Guide system</a> is micro-prompting
assistive technology which helps people to complete the tasks of
daily living. It allows you to create a flowchart detailing how to
talk a user through completing a task. Guide gives prompts and asks
questions via speech synthesis. Users answer yes or no as they
progress through the problem space. Guide ensures that the user
sequences the task correctly. Guide helps users to live
independently without the need for human help when completing tasks
such as the morning routine, making tea, or using the washing
machine.</p>

<p>Anyway, at the moment the Guide system is a cross-platform
mobile app which runs on both iOS and Android devices. It downloads
the activities from the server, and uses local voice recognition on
the device, so that it can work in an offline environment. Users
can also schedule the activities on the device, for example the
morning routine can kick in at the same time every day.</p>

<p>You can <a
href="https://guide-research.com/guide/index.html#/signup/"
target="_blank" title="Sign up for Guide">sign up for Guide</a> and
download the Android app for your device to try it out (you'll need
to get in touch if you're on iOS).</p>

<p>Our original assumption when we built this iteration of Guide
was that not all users would have reliable internet connections.
That is why we decided to use offline voice recognition. This
assumption now seems out of date. With the advent of the new
voice-activated devices like the Amazon Echo and Google Home, it
seems that voice has truly arrived into people's homes.</p>

<p>This is why we have our eye on the Alexa system for the next
iteration of Guide. We could leverage the excellent voice
recognition capabilities of the device, which are constantly being
improved by Amazon. So as a first step I've created a skill to
demonstrate Guide on Alexa so that we can prove it works and see
how users like it. It's written completely within the Alexa system,
using <a href="https://nodejs.org/en/" target="_blank"
title="NodeJs">Node.js</a>, and sitting on <a
href="https://aws.amazon.com/lambda/" target="_blank"
title="AWS Lambda">AWS Lambda</a>. It's based on a much-simplified
tea-making activity, and you can try it out for yourself:</p>

<p><a
href="https://www.amazon.co.uk/Web-Garden-Limited-Tea-Guide/dp/B076JGKSLJ"
 target="_blank" title="Tea Guide skill for Alexa">Tea Guide (UK
version)</a> (or <a
href="https://www.amazon.com/Web-Garden-Limited-Tea-Guide/dp/B076JGKSLJ"
 target="_blank" title="Tea Guide skill for Alexa (US version)">US
version</a>)</p>

<p>We'd love to hear your feedback!</p>
]]></content:encoded></item><item><title>Releasing mobile apps is hard</title><link>http://web-garden.co.uk//blog/2016/6/23/releasing-mobile-apps-is-hard</link><pubDate>Thu, 23 Jun 2016 09:57:48 GMT</pubDate><guid>http://web-garden.co.uk//blog/2016/6/23/releasing-mobile-apps-is-hard</guid><description>Certified Umbraco Developer | David Conlisk | Web Garden | blog entry</description><content:encoded><![CDATA[ 
<p>Releasing mobile apps takes time. Lots of time. Getting the app
to work on the devices you are targetting is only the beginning.
Take for example the <a href="http://limbactivator.com"
target="_blank" title="Limb Activator">Limb Activator app</a> that
I just released as a side project. It's a very simple app: if the
device doesn't sense movement for a specified period of time, it
buzzes or beeps. That's it. <strong>The prototype took less than 3
hours to create on iOS</strong>, on a train journey from London to
Glasgow. In the end it took just shy of 100 hours of my time to
complete, and that's not including some time from a designer friend
to do some image manipulation and icon design (which I paid for, of
course).</p>

<p>So what did I spend the other 97 hours doing? Here's a list of
some of the things:</p>

<p>- The UI for the app. I used the excellent <a
href="http://grialkit.com/" target="_blank"
title="Xamarin Forms UI Kit">Grialkit</a> Xamarin Forms UI kit
which basically gives you a set of layouts that you can use out of
the box. Just tweak the colours and away you go.</p>

<p>- Images. <strong>Lots and lots of images.</strong> Take an
image, and make hundreds of versions of it, to satisfy iOS,
Android, Google Play and the App Store. Oh, and don't forget the
website...</p>

<p>- A responsive website. Go get yourself a cheap skin, then you
realise when you add extra text the layout is screwed.
<strong>Spend hours tweaking css.</strong> And don't forget to
include screenshots of the app on the site. I didn't create a
responsive website for the <a
href="http://www.bristolstoolchart.net" target="_blank"
title="Bristol Stool Chart poop app">Bristol Stool Chart app</a>, I
just updated the app images, screenshots, and logo for the old site
- and believe me, that was enough.</p>

<p>- Marketing. Set up a Twitter account. Create a Facebook page.
Find ways to get the word out. <strong><strong>If you build it,
they will</strong> NOT come</strong>, at least not unless you
market it properly. I used the <a href="https://www.tweetliker.com"
target="_blank" title="TweetLiker">TweetLiker</a> tool to find
twitter accounts to like and follow as a way of getting the word
out. It's a very nice tool, but I'm not sure how effective that
strategy is - yet. It is a definite improvement on having to Google
for relevant sites for the original Bristol Stool Scale app in 2011
that's for sure!</p>

<p>- Testing. This can take a lot of time. Thankfully you can use
simulators to test your layouts on different screen sizes, but
nothing beats testing on a real device (I haven't used <a
href="https://www.xamarin.com/test-cloud" target="_blank"
title="Xamarin Test Cloud">Xamarin Test Cloud</a>). Also the
technology moves very quickly, so if you get side-tracked (by paid
work, for example) when you come back to your project you may find
that there are software updates to be installed, and who knows what
effect they might have? Also, when using plugins you never know how
buggy they might be, or how quickly your pull requests will be
accepted into the project.</p>

<p>- The App Stores. <strong>Getting your app accepted can be
tricky</strong>, especially with Apple, and can be time-consuming.
In the past I've waited over a week for the Apple review process
for an app update to complete. Thankfully, that is more like a day
just now. Remember that just because you can build and run your app
in Release mode on your device, doesn't mean that your app will
satisfy all criteria for either of the app stores.</p>

<p>So I suppose what I'm saying here is, if you're going to build a
mobile app in your spare time or as a side project or even as a
business venture, <strong>make sure you believe in it.</strong>
Because when the exciting part (the working app) is over, you're
not even close to being finished yet.</p>

<h4>But what about the technology?</h4>

<p>My experience with Xamarin in the past was using the excellent
<a href="https://github.com/MvvmCross/MvvmCross" target="_blank"
title="MvvmCross framework">MVVMCross framework</a> so getting to
use <a href="https://www.xamarin.com/forms" target="_blank"
title="Xamarin Forms">Xamarin.Forms</a> was part of my motivation.
I wanted to see if it was any good. And it was great! I was
especially impressed with the number of plugins already available
to use with Xamarin.Forms:</p>

<p><a href="https://github.com/xamarin/XamarinComponents"
target="_blank"
title="Xamarin Components">https://github.com/xamarin/XamarinComponents</a></p>

<p><a href="https://github.com/jamesmontemagno/Xamarin.Plugins"
target="_blank"
title="Xamarin Plugins">https://github.com/jamesmontemagno/Xamarin.Plugins</a></p>

<p><a
href="https://blog.xamarin.com/amazing-community-built-plugins-for-xamarin/"
 target="_blank"
title="Community built Xamarin plugins">https://blog.xamarin.com/amazing-community-built-plugins-for-xamarin/</a></p>

<p>I also used <a href="http://grialkit.com/" target="_blank"
title="Xamarin Forms UI Kit">Grialkit</a>, because my design skills
are non-existent. It really helped me a lot, reducing my design
costs substantially, and allowing me to quickly create good looking
UIs. <strong>Nothing will replace a top-notch designer</strong>,
but for my purposes Grialkit was excellent. Also, I can't praise
their support highly enough. The only thing to note here is that
you need to use their kit as a starting point, rather than
integrating it with your existing code - something to bear in
mind.</p>

<h4>In summary</h4>

<p>If you're going to build an app, be prepared for all of the
"other stuff" that needs to be done alongside getting your app to
work. Use Xamarin Forms, use Grialkit, use Tweetliker, they are all
great tools. <strong>Just don't forget to market your
app!</strong></p>
]]></content:encoded></item><item><title>PocketSphinx binding for Xamarin</title><link>http://web-garden.co.uk//blog/2014/6/2/pocketsphinx-binding-for-xamarin</link><pubDate>Mon, 02 Jun 2014 10:43:49 GMT</pubDate><guid>http://web-garden.co.uk//blog/2014/6/2/pocketsphinx-binding-for-xamarin</guid><description>Certified Umbraco Developer | David Conlisk | Web Garden | blog entry</description><content:encoded><![CDATA[ 
<p>I have created a Xamarin Java Bindings library for PocketSphinx
so that I can use PocketSphinx voice recognition in my Xamarin
Android app. <a
href="http://stackoverflow.com/questions/22765688/creating-and-using-java-bindings-library-for-pocketsphinxandroiddemo/22785174"
 target="_blank"
title="Creating and using Java Bindings library for PocketSphinxAndroidDemo">
I was asked on Stack Overflow</a> to share it, so here it is!</p>

<p><a href="/media/20336/pocketsphinxdroid.zip"
title="Xamarin Java bindings library for PocketSphinx">Download the
Xamarin Java bindings library for PocketSphinx</a></p>

<p>(Please note, this works in my particular case, but I am giving
you no guarantees that it will work in yours - use at your own
risk!)</p>
]]></content:encoded></item><item><title>Themebraco launched!</title><link>http://web-garden.co.uk//blog/2014/5/29/themebraco-launched!</link><pubDate>Thu, 29 May 2014 11:52:23 GMT</pubDate><guid>http://web-garden.co.uk//blog/2014/5/29/themebraco-launched!</guid><description>Certified Umbraco Developer | David Conlisk | Web Garden | blog entry</description><content:encoded><![CDATA[ 
<p>-</p>

<p><strong>Unfortunately Themebraco development has been
discontinued. You can check out the good stuff from the guys at <a
href="https://uskinned.net/" target="_blank"
title="Umbraco themes">uSkinned</a> instead though :)</strong></p>

<p>-</p>

<p>We are very pleased to announce that we have launched <a
href="http://www.themebraco.com" target="_blank"
title="Umbraco themes">Themebraco.com</a> - <span>the home of
premium themes, exclusively for the Umbraco platform.
Professionally designed, expertly built, responsive site templates
which are super-quick to install.</span></p>

<p><span><a href="http://www.themebraco.com" target="_blank"
title="Umbraco themes">Visit the Themebraco site to sign up</a> to
our mailing list to be the first to get a peek at our responsive
themes for Umbraco as soon as we launch the full site. At the
moment we are keeping the technical details to ourselves, but we
think that this is going to be the new way to quickly and
economically create new Umbraco sites that are both beautiful to
look at and beautiful to use.</span></p>

<p><span>We're very excited and looking forward to sharing our
beautiful new themes with the Umbraco community!</span></p>

<p><strong>UPDATE:</strong> To see just how easy it is to use a
Themebraco theme, have a look at this short screenr which shows you
how we built the Themebraco landing page:</p>

<p><a href="http://www.screenr.com/9ECN" target="_blank"
title="Themebraco themes for Umbraco">How we built the Themebraco
landing page</a></p>

<p><strong>SURVEY:</strong> What would you like to see included in
a custom theme for Umbraco? What is essential? Contact form? Blog?
What would you see as an added extra? Leave your suggestions in the
comments! :)</p>
]]></content:encoded></item><item><title>Generating thumbnail images for PDFs in Umbraco</title><link>http://web-garden.co.uk//blog/2013/4/18/generating-thumbnail-images-for-pdfs-in-umbraco</link><pubDate>Thu, 18 Apr 2013 17:13:43 GMT</pubDate><guid>http://web-garden.co.uk//blog/2013/4/18/generating-thumbnail-images-for-pdfs-in-umbraco</guid><description>Certified Umbraco Developer | David Conlisk | Web Garden | blog entry</description><content:encoded><![CDATA[ 
<p>Sometimes you want to display thumbnail images beside a list of
PDF files on your website. It's possible to create thumbnails
automatically from PDFs using the <a
href="https://github.com/mephraim/ghostscriptsharp" target="_blank"
title="GhostScriptSharp on Github">GhostscriptSharp</a> tool. I'll
show you how to get this to happen automatically in Umbraco.</p>

<p>To have something happen automatically in Umbraco, you can hook
into an event. For my purposes, I used the Media.AfterSave event.
This way any time a pdf document is uploaded or updated in the
media section, I create a thumbnail file based on the first page of
that document and store it on the file server. If you name it
correctly, it will even appear next to your pdf in the Umbraco
media section.</p>

<p>To use the GhostscriptSharp tool, just copy the
GhostscriptSharp.dll and gsdll32.dll files from the
GhostscriptSharp project (which you can <a
href="https://github.com/mephraim/ghostscriptsharp" target="_blank"
title="Download GhostscriptSharp">download as a zip</a>) into the
bin directory of your Umbraco site. Then add references to both of
those dlls to your UserControls project. Now add your event handler
to your UserControls project, so that it will be compiled into your
UserControls.dll file and copied into your Umbraco site. Umbraco is
smart enough to find any event handlers that implement the correct
interfaces in your compiled code - you don't need to do anything
else. The code for my event handler is shown below.</p>

<p>Please note! This has only been tested in Umbraco 4.9.x and
4.11.x.</p>

<p>I also had to do two other things. Firstly, make sure that the
application pool for your website is set to enable 32-bit
applications (you can find that setting in the Advanced Settings in
IIS7). I also had to remove the System.Data.SQLite.dll from the bin
folder of my Umbraco site when I made the change to the application
pool. I haven't noticed any side-effects.</p>

<p>And so, here is the code for the event handler. Enjoy!</p>

<pre class="brush: csharp">
public class CreatePdfThumbnail : IApplicationStartupHandler
    {
        public CreatePdfThumbnail()
        {
            Media.AfterSave += CreateThumbnail;
        }

        private static void CreateThumbnail(Media sender, SaveEventArgs e)
        {
            if (sender.getProperty("umbracoFile") != null &amp;&amp; sender.getProperty("umbracoFile").Value != null &amp;&amp;
                !string.IsNullOrEmpty(sender.getProperty("umbracoFile").Value.ToString()))
            {
                try
                {
                    var fullPath = sender.getProperty("umbracoFile").Value.ToString();
                    var fileName = Path.GetFileName(fullPath);
                    var filePath = fullPath.Replace(fileName, "");
                    var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fullPath);
                    GhostscriptWrapper.GeneratePageThumb(HttpContext.Current.Server.MapPath( sender.getProperty("umbracoFile").Value.ToString()), HttpContext.Current.Server.MapPath(String.Format("{0}{1}_thumb.jpg", filePath, fileNameWithoutExtension)), 1, 7, 8);
                }
                catch (Exception ex)
                {
                    // Log error to Elmah - optional ;)
                    Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                }
            }
        }
    }
</pre>
]]></content:encoded></item><item><title>Intellisense for Umbraco tags in your User Controls in Visual Studio</title><link>http://web-garden.co.uk//blog/2013/4/17/intellisense-for-umbraco-tags-in-your-user-controls-in-visual-studio</link><pubDate>Wed, 17 Apr 2013 13:55:21 GMT</pubDate><guid>http://web-garden.co.uk//blog/2013/4/17/intellisense-for-umbraco-tags-in-your-user-controls-in-visual-studio</guid><description>Certified Umbraco Developer | David Conlisk | Web Garden | blog entry</description><content:encoded><![CDATA[ 
<p>It's been bugging me for ages, and on my current project seemed
especially annoying. When I try to place an Umbraco tag (e.g.
umbraco:Macro or umbraco:Item) in my .NET user controls in my User
Controls project in Visual Studio, they are not recognised as valid
tags. This is what I get:</p>

<p><img src="/media/19225/codesnippet1_589x144.png" width="589" height="144" alt="VS Intellisense Before"/></p>

<p>The fix is simple. Just add a web.config to your User Controls
project (or update your existing one, if you have one), with the
following content:</p>

<pre class="brush: xml">
&lt;?xml version="1.0"?&gt;
&lt;configuration&gt;
    &lt;system.web&gt;
      &lt;pages&gt;
        &lt;controls&gt;
          &lt;add tagPrefix="umbraco" namespace="umbraco.presentation.templateControls" assembly="umbraco" /&gt;
        &lt;/controls&gt;
      &lt;/pages&gt;
    &lt;/system.web&gt;
&lt;/configuration&gt;
</pre>

<p>Now you should have full intellisense for your Umbraco tags in
your User Controls. Check it out - much better I think you'll
agree:</p>

<p><img src="/media/19231/codesnippet2_589x144.png" width="589" height="325" alt="VS Intellisense After"/></p>

<p>Thanks to <a href="http://www.twitter.com/StephenWRogers"
target="_blank"
title="Stephen Rogers on Twitter">@StephenWRogers</a> for his input
on this one.</p>
]]></content:encoded></item><item><title>How to install Umbraco from scratch using nuget in Visual Studio</title><link>http://web-garden.co.uk//blog/2013/2/5/how-to-install-umbraco-from-scratch-using-nuget-in-visual-studio</link><pubDate>Tue, 05 Feb 2013 12:54:57 GMT</pubDate><guid>http://web-garden.co.uk//blog/2013/2/5/how-to-install-umbraco-from-scratch-using-nuget-in-visual-studio</guid><description>Certified Umbraco Developer | David Conlisk | Web Garden | blog entry</description><content:encoded><![CDATA[ 
<p>I was <a
href="http://our.umbraco.org/forum/getting-started/installing-umbraco/38110-Installing-Umbraco-v6-using-nuget-fails"
 target="_blank"
title="Installing Umbraco v6 using nuget fails">having some
trouble</a> working out how to install Umbraco in a clean, new
visual studio project. Here's how to do it.</p>

<h4>Assumptions</h4>

<p>I'm assuming that you are using Visual Studio 2010 (I know - old
school) and that you have nuget installed. Find out <a
href="http://docs.nuget.org/docs/start-here/installing-nuget"
target="_blank" title="How to install nuget">how to install
nuget</a> if you don't already have it. It's great!</p>

<p><strong>Update:</strong> MVC is a dependency that is
automatically "bin-deployed" so you don't have to worry about that
part (Thanks for the info Sebastiaan!)</p>

<h4>Instructions</h4>

<ul>
<li>Open up VS2010.</li>

<li>Choose File -&gt; New Project... -&gt; <strong>ASP.NET MVC 4
Web Application</strong> or <strong>ASP.NET Web
Application</strong> <strong>(thanks again Seb!)</strong></li>

<li>Enter a name for your application and a location.</li>

<li>Click OK.</li>

<li>Choose the Empty project template, and accept the default view
engine (i.e. Razor).</li>

<li>Click OK.</li>

<li>Open up nuget package manager by going to Tools -&gt; Library
Package Manager -&gt; Package Manager Console.</li>

<li>Type the command at the prompt: <strong>install-package
umbracocms</strong></li>

<li>When nuget has done its thing, hit F5 to enjoy your brand
spanking new Umbraco website! (you may get a popup message about
your web.config and debugging, just accept it and continue).</li>
</ul>

<p><strong>UPDATE April 4th, 2013:</strong> If you are using VS2012
with this method, double-check the web.config in the Views folder.
See <a
href="http://our.umbraco.org/forum/developers/razor/38549-Umbraco-60-mvc-no-definition-for-BeginUmbracoForm?p=0#comment145384"
 target="_blank"
title="Umbraco 6.0 mvc no definition for BeginUmbracoForm">my post
on the forum</a> for more information.</p>
]]></content:encoded></item><item><title>24 Days In Umbraco Christmas Calendar</title><link>http://web-garden.co.uk//blog/2012/12/2/24-days-in-umbraco-christmas-calendar</link><pubDate>Sun, 02 Dec 2012 11:47:13 GMT</pubDate><guid>http://web-garden.co.uk//blog/2012/12/2/24-days-in-umbraco-christmas-calendar</guid><description>Certified Umbraco Developer | David Conlisk | Web Garden | blog entry</description><content:encoded><![CDATA[ 
<p>I was asked to contribute to the <a
href="http://24days.in/umbraco/2012/doctypemixins/" target="_blank"
title="24 Days in Umbraco Christmas">24 Days in Umbraco Christmas
Calendar 2012</a>. I made a short screencast about one of my
favourite Umbraco packages, <a
href="http://our.umbraco.org/projects/backoffice-extensions/doctypemixins"
 target="_blank"
title="Umbraco DocTypeMixins package">DocTypeMixins</a>. It's based
on a talk I gave at the last Glasgow Umbraco Users Group (GLUUG)
meeting, so apologies if you've seen it before! You can <a
href="http://24days.in/umbraco/2012/doctypemixins/" target="_blank"
title="DocTypeMixins screencast">view the video on the 24 Days in
Umbraco site</a>. Don't forget to check back every day in December
as new items are added every day from members of the Umbraco
community.</p>

<p><a href="http://our.umbraco.org/events/gluug" target="_blank"
title="Glasgow Umbraco Users Group meeting">The next meeting of
GLUUG will be on December 6th</a>. If you're anywhere near Glasgow,
come along for a drink and a chat and meet some of the Glasgow
Umbraco folk face to face!</p>
]]></content:encoded></item><item><title>How to control the page orientations in your iOS PhoneGap application part 2</title><link>http://web-garden.co.uk//blog/2012/7/29/how-to-control-the-page-orientations-in-your-ios-phonegap-application-part-2</link><pubDate>Sun, 29 Jul 2012 19:19:36 GMT</pubDate><guid>http://web-garden.co.uk//blog/2012/7/29/how-to-control-the-page-orientations-in-your-ios-phonegap-application-part-2</guid><description>Certified Umbraco Developer | David Conlisk | Web Garden | blog entry</description><content:encoded><![CDATA[ 
<p><strong>UPDATE:</strong> A number of commenters tell me that
this doesn't work with iOS 6 or Cordova 2.1. This was developed
using iOS5 and Cordova 2.0. If anyone finds a way to make it work
for the latest versions please let me know in the comments!</p>

<p>Okay so you've read <a href="/blog/2012/7/26/how-to-control-the-page-orientations-in-your-ios-phonegap-application"
title="How to control the page orientations in your iOS PhoneGap application">
my previous blog post about page orientation in your PhoneGap
application</a> (of course) but you realise, like I did, that
although you've managed to prevent the device from going into
landscape mode on certain pages in your app, it's still not a
flawless solution. Users can still go to, for example, the graph
page, flip their phone into landscape, then browse back to your
home page et voila - it's being displayed in landscape! So how to
prevent this?</p>

<p><strong>Please note that I'm assuming you're using PhoneGap
(Cordova) v2.0.0 here.</strong></p>

<p>This part is a bit trickier and I had to hack the existing <a
href="https://github.com/acti0nm4n/Phonegap-Orientation-iOS"
target="_blank" title="PhoneGap Orientation plugin">PhoneGap
Orientation plugin</a> to get this to work. I've simplified it
slightly. You just need to add the Orientation class (see below for
the code) to your project, then call it from javascript to force
the rotation of the screen when your page changes in your PhoneGap
application. So in my case, for every screen except the graph
screen, I would call to the plugin to rotate to portrait
orientation. This way if a user was in landscape orientation when
viewing the graph screen, and was holding the phone in landscape
orientation, and clicked the home link, the orientation would
switch back to portrait (because of my javascript call).</p>

<p>I've included my code below.</p>

<p>1. I added Orientation.h and Orientation.m into the Plugins
folder in my PhoneGap 2.0 project.</p>

<p>2. I updated the Cordova.plist file and added a new entry in the
Plugins section, key "orientation" and value "Orientation".</p>

<p>3. Then in my javascript I did this when loading a page, to
force all pages except my graph page into portrait orientation:</p>

<pre class="brush: csharp">
// If we're on the graph page, then ensure content rotates to current physical device orientation
        if (viewname == "graph") {
            switch(window.orientation) 
            {  
                case -90:
                    options = [{landscapeleft:true}];
                    break;
                case 90:
                    options = [{landscaperight:true}];
                    break;
                case 180:
                    options = [{portraitdown:true}];
                    break;
                default:
                    options = [{portrait:true}];
                    break;
            }   
        }
        else {
            // Not on graph page, so flip to portrait regardless of physical device orientation
            options = [{portrait:true}];
        }
        
        cordova.exec(null, null, "Orientation", "setOrientation", options);
</pre>

<p><strong>Orientation.h</strong></p>

<pre class="brush: csharp">
#import &lt;Cordova/CDVPlugin.h&gt;

@interface Orientation : CDVPlugin {
    
}

//Instance Method  
- (void) setOrientation:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;

@end
</pre>

<p><strong>Orientation.m</strong></p>

<pre class="brush: csharp">
//
//  SetOrientation.m
//  
#import "Orientation.h" 
#import &lt;Cordova/CDVPluginResult.h&gt;

@implementation Orientation 


// Called from javascript, set the orientation to Portrait when going from graph screen (in Landscape) back
// to other screens - doesn't happen automatically because the physical orientation of the devicehasn't changed
- (void)setOrientation:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options  
{
    //self.viewController.supportedOrientations = arguments;
    NSLog(@"Rotating device in code");

    // Wrap it all in an animation so it looks nicer
    [UIView beginAnimations:@"rotate" context:NULL];
    [UIView setAnimationDelegate:self];
    
    //will rotate status bar
    if ([[options objectForKey:@"portrait"] intValue] == 1) {
        NSLog(@"Portrait");
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
    }
    else if ([[options objectForKey:@"portraitdown"] intValue] == 1) {
        NSLog(@"Portrait UpsideDown");
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortraitUpsideDown];
    }
    else if ([[options objectForKey:@"landscapeleft"] intValue] == 1) {
        NSLog(@"Landscape Left");
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
    }
    else if ([[options objectForKey:@"landscaperight"] intValue] == 1) {
        NSLog(@"Landscape Right");
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
    }
    else {
        NSLog(@"Not defined");
    }
    
    //will re-rotate view according to statusbar
    UIViewController *c = [[UIViewController alloc]init];
    [self.viewController presentModalViewController:c animated:NO];
    [self.viewController dismissModalViewControllerAnimated:NO];
    [c release];
    
    [UIView commitAnimations];
}

@end
</pre>

<p>So hopefully you find that helpful. It's strange that there is
no easy way to achieve this, I would have thought that this was a
feature many developers would want for their PhoneGap applications
but I found it surprisingly difficult to work this one out.</p>
]]></content:encoded></item><item><title>How to control the page orientations in your iOS PhoneGap application</title><link>http://web-garden.co.uk//blog/2012/7/26/how-to-control-the-page-orientations-in-your-ios-phonegap-application</link><pubDate>Thu, 26 Jul 2012 17:29:47 GMT</pubDate><guid>http://web-garden.co.uk//blog/2012/7/26/how-to-control-the-page-orientations-in-your-ios-phonegap-application</guid><description>Certified Umbraco Developer | David Conlisk | Web Garden | blog entry</description><content:encoded><![CDATA[ 
<p>In your PhoneGap application for iOS, you only have a single
html page, with javascript controlling the navigation within your
application. This means that you cannot set the allowed
orientations natively in iOS - because there is only a single page
for your whole application. But what if you want to allow parts of
your application to be viewed in landscape, but not others?</p>

<p>I looked into a number of solutions including css and
javascript, but nothing seemed to work properly. The css and
javascript solution worked, but I felt that the result was a bit
shoddy to say the least. The only proper way would be to do it
natively.</p>

<p>The key to this solution is the function</p>

<pre class="brush: csharp">
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
</pre>

<p>in MainViewController.m. Here is where you specify which
orientations are allowed for your view. My first thought was that I
could check the current URL of the UIWebView (which typically just
points at your www/index.html file) for any anchors, e.g.
www/index.html#myPage, which would let me know which page I'm on.
Unfortunately,</p>

<pre class="brush: csharp">
self.webView.request.URL.fragment
</pre>

<p>always returns null. It turns out that the UIWebView helpfully
ignores the fragment, i.e. the hash tags, so I was out of luck.
Then I started investigating the</p>

<pre class="brush: csharp">
stringByEvaluatingJavaScriptFromString
</pre>

<p>function provided by UIWebView. You can use this function to
call a javascript function in your view, and then have the return
value available in your native code. So the solution is to ask
javascript in the UIWebView what page we're on, and if it's the
graph page (in my case) then allow landscape orientation.
Otherwise, don't.</p>

<p>This is a reasonably simple solution in the end but it took
hours of Googling and trial and error to get it right. Here's
hoping you find it useful!</p>

<p>Here is my javascript function, which is included on the page
being displayed in the UIWebView (typically www/index.html);</p>

<pre class="brush: csharp">
function isGraphPage() {
return (window.location.href.indexOf("#graph") &gt; -1);
}
</pre>

<p>And here is my function in MainViewController.m:</p>

<pre class="brush: csharp">
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
NSString *isGraphPage = [self.webView stringByEvaluatingJavaScriptFromString: @"isGraphPage();"];
NSString *truth = @"true";
if ([isGraphPage isEqualToString:truth]) {
// Allow all orientations allowed globally for the app if we're on the graph page
return [super shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
else {
// Only allow portrait orientation for all other pages
return interfaceOrientation==UIInterfaceOrientationPortrait;
}
}
</pre>

<p><strong>UPDATE:</strong>I realised that this was only half the
battle. Now your user can't enter landscape orientation when
viewing any page other than the graph page. But what they can do is
enter landscape orientation on the graph page, then browse to
another page in your app, and hey! they've managed to view it in
landscape mode. <a href="/blog/2012/7/29/how-to-control-the-page-orientations-in-your-ios-phonegap-application-part-2"
title="How to control the page orientations in your iOS PhoneGap application part 2">
Read part 2 of the solution to this problem and fully control the
page orientation in your PhoneGap application</a>.</p>
]]></content:encoded></item></channel></rss>
