Monday, September 29, 2014

Xamarin Error:No valid iOS code signing keys found in keychain

Problem:

I got this lovely error when trying to do my hello world program.  I just managed to complete the configuration of our development network and needed to test the iPhone compilation within Visual Studio.

When I went to build I got this error: No valid iOS code signing keys found in keychain

After some research, I found the Xamarin forums quite helpful and located this guide:
http://docs.xamarin.com/guides/ios/getting_started/device_provisioning/

The issue is the compiler on the Mac Host is trying to build out the final package for deployment to an iPhone device.  You need to register with as an Apple developer to do that.  Forunately or Unfortuantely, we are not ready to do that just yet with our App.

My issue was why can't I run the emulator in Visual Studio?

Solution:
  1. Right-click the Standard toolbar (the one which has the current configuration drop-down saying Debug, Release etc) and choose Customize… from the menu:
    [ ]
  2. Switch to the Commands tab.
  3. Select the Toolbar radio button
  4. Select the Standard toolbar in the list to the right of the radio button
  5. Scroll down the Controls widget till you see the Solution Configurations widget and select it
  6. Click the Add command... button:
    [ ]
  7. Choose the Build category
  8. Choose the Solution Platforms command and click OK :
    [ ]
  9. Click Close




Source:
http://developer.xamarin.com/guides/ios/getting_started/installation/windows/



Friday, September 26, 2014

Xamarin Error 429 - clocks not synced

I am building out a disconnected network for our VS/Xamarin iOS build environment. 

Problem:
I have successfully paired the Mac and Windows boxes on our local network.  I noted that there is a discrepancy in the clocks between the two machines.  How to fix this problem.

Solution:
Make your Mac the time server

  1. Unload the current npd daemon.
    • sudo launchctl unload /System/Library/LaunchDaemons/org.ntp.ntpd.plist 
  2. Edit the ntp-restrict.conf
    • /etc/ntp-restrict.conf
    • Remove the “noquery” from the 1st two restrict lines:
  3. Now load the npd file again
    • sudo launchctl load /System/Library/LaunchDaemons/org.ntp.ntpd.plist
  4. Test npd to ensure it is running
    • sudo ntpdate -u localhost
On your Windows PC
  1. Open Date and Time Dialog
  2. Select the Internet time tab
  3. Change Settings
  4. Select Synchronize with and Internet time server.
  5. Place the IP Address of the Mac you are using as the time server (192.168.0.100) in the Server block
  6. Update Now
  7. OK
Now
  1. Open up command window as admin
  2. type in command: w32tm /config /manualpeerlist:192.168.0.100 /syncfromflags:MANUAL
 Now the windows box will sync its time with the Mac box and should not have the 429 errors any longer.


Source
http://macmule.com/2013/12/15/how-to-use-osx-server-as-a-time-server/

The remote server returned an error: 429 (Xamarin Visual Studio iOS error 429)

Problem:
VS not working (The remote server returned an error: 429)

Solution:
My clocks were off by one hour inspite of showing the same time.  The windows box had an incorrect setting for the timezone UTC+1.  It had been manually advanced by one hour.  This meant that the times between the Windows box running VS and the Mac Host had a difference of 1 hour.
Anything over 3 minutes will throw an error in the compiler.






http://forums.xamarin.com/discussion/17062/vs-not-working-the-remote-server-returned-an-error-429

Tuesday, September 23, 2014

Installing Xamarin.iOS on Windows

Xamarin site has great how to guides for installing their product for use with Visual Studio.
We are writing our first iPhone app using C#, Xamarin and Mvvmcross.




How to install:

http://developer.xamarin.com/guides/ios/getting_started/installation/windows/#Connecting_to_the_Mac_Build_Host

Setting up Mac OS 10.9 Mavericks as a DHCP server.

As part of our iPhone Xamarin project, we are setting up a disconnected network.  I had a linksys switch but needed to get DHCP going on our internal network.  Fortunately, this has already been done.

How to
1.)  Enable root user on Mavericks
  • Launch The System Preference Application
  • Open Users & Groups preferences, click Login Options, then click the lock icon to unlock it. If necessary, type your password, then click Unlock.
  • In the Network Account Server section, click Join or Edit.
  • Click Open Directory Utility.
  • Click the lock icon to unlock it, then enter your administrator name and password.
  • Choose Edit > Enable Root User, then enter a root user password in the Password and Verify fields.
  • Close the Directory Utility Application.
2.) Configure bootpd on Mavericks.  The post by Jacques Fortier does a great job explaining each step.
  • To start, you need to create a configuration file for the server. The file should be stored in /etc/bootpd.plist.
Sample:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>bootp_enabled</key>
    <false/>
    <key>detect_other_dhcp_server</key>
    <integer>1</integer>
    <key>dhcp_enabled</key>
    <array>
        <string>en0</string>
    </array>
    <key>reply_threshold_seconds</key>
    <integer>0</integer>
    <key>Subnets</key>
    <array>
        <dict>
            <key>allocate</key>
            <true/>
            <key>lease_max</key>
            <integer>86400</integer>
            <key>lease_min</key>
            <integer>86400</integer>
            <key>name</key>
            <string>192.168.33</string>
            <key>net_address</key>
            <string>192.168.33.0</string>
            <key>net_mask</key>
            <string>255.255.255.0</string>
            <key>net_range</key>
            <array>
                <string>192.168.33.2</string>
                <string>192.168.33.254</string>
            </array>
        </dict>
    </array>
</dict>
</plist>
  • To start the server, run the following command:
    sudo /bin/launchctl load -w /System/Library/LaunchDaemons/bootps.plist
  • Stopping the server is very similar:
    sudo /bin/launchctl unload -w /System/Library/LaunchDaemons/bootps.plist


Source:

How to simulate a low-bandwidth connection or poor signal for Windows Phone 8

Problem:

Testing the Windows Phone with limited bandwidth for cell coverage has been something you need to do with a device attached to a VS debug session.  This obviously is not an optimal solution.  Visual Studio now has the Simulation Dashboard.

Solution:

To open the Simulation Dashboard, in Visual Studio, on the Tools menu, click Simulation Dashboard. After you open the dashboard, it remains open and available even when you open and close projects in Visual Studio.

Source
  1. http://msdn.microsoft.com/en-us/library/windows/apps/jj206952(v=vs.105).aspx

Tuesday, September 16, 2014

MVVM and Windows Phone application bar

Working a cross platform mobile solution.  I have the Commands defined in my mvvm core View Model.  I need to bind my View in the Windows Phone 8 application to the command in the ViewModel. 

Problem:
"Windows Phone AppBar's are naive rather than Silverlight controls - so they are not bindable"

Solution:
Get an addon which will support app bar binding for windows phone 8. 
https://bindableapplicationb.codeplex.com/


Source:
http://stackoverflow.com/questions/25466816/how-to-do-binding-for-a-global-applicationbar-in-windows-phone-with-mvvmcross

Wednesday, September 10, 2014

Xaml Binding EventToCommand to MVVM core

I have worked my way through Stuart Lodge's N+1 tutorials.
I was stumped about how to connect my Icommand control from the core to the UI.
Stuart's demo showed how to connect a button or checkbox to the MvxCommand but did not explain how to use the EventToCommand relationship.

I was trying to have a stackpanel fire the event when the user taps it in the UI.
The stackoverflow article provided me the leg up I needed.

I was struggling on which syntax to use to associate a stackpanel in xaml with my command. Turns out I needed to reference the Cirrious namespace in the xaml


xmlns:Commands="clr-namespace:Cirrious.MvvmCross.WindowsPhone.Commands;assembly=Cirriou... xmlns:Commands="clr-namespace:Cirrious.MvvmCross.WindowsPhone.Commands;assembly=Cirrious...

<i:Interaction.Triggers >
   <i:EventTrigger EventName="Tap">
      <Commands:MvxEventToCommand Command="{Binding OnItemTappedCommand}" />
   </i:EventTrigger >
</i:Interaction.Triggers>
Source:
http://stackoverflow.com/questions/16823444/im-getting-build-errors-when-using-mvxeventtocommand-within-a-wp8-project

https://github.com/MvvmCross/MvvmCross/blob/e6d10972b5c28e00e80acc3d9e8910961aa813d6/Cirrious/Cirrious.MvvmCross.WindowsPhone/Commands/MvxEventToCommand.cs


Awesome MvvmCross tutorial from Stuart Lodge

Stuart has posted an amazing series of videos on youtube.  He explains how mvvmcross templates interacts with the Xamarin templates.  This is some great information.
https://www.youtube.com/watch?v=He6QvnLsPUA&list=PLR6WI6W1JdeYSXLbm58jwAKYT7RQR31-W&index=7

iPhone development in C#

Starting a project to develop an iPhone application.  We are going to pursue a cross platform solution using Xamarin software.  This should allow us to write the core processes in C# and deploy UIs specific to the platform we are targeting.  In order to get the most out of the design, we are going to use the MVVM pattern.  MVVMCross is a github project which used in concert with Xamarin software will allow us to write C# for both back end and UI.

This promises to be an exciting project.  We currently have 2 versions of the application written (WP8, Android).  These were done without the benefit of this approach and will at some point be migrated to this pattern. 

Wednesday, September 3, 2014

MVVMCross - Could not install package 'MvvmCross.PortableSupport 3.1.1'.

MVVM Cross nuget package 3.1.1 with VS 2012 SP2 not working

Error:

Could not install package 'MvvmCross.PortableSupport 3.1.1'. You are trying to install this package into a project that targets 'portable-net45+sl40+wp+win', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

Explanation:

The problem is that MvvmCross.PortableSupport 3.1.1 has a portable class library that targets:
portable-win+net45+sl50+wp8+MonoAndroid+MonoTouch
Whilst your portable class library project is targeting:
portable-win+net45+sl40+wp71
The MonoAndroid and MonoTouch frameworks are optional and will not be used in the comparison if you are using NuGet 2.7.2 or above. Your project is targeting Silverlight 4.0 and Windows Phone 7.1 whilst MvvmCross.Portable is targeting Silverlight 5.0 and Windows Phone 8. So it is not compatible. You cannot install a portable class library into a portable class library project that targets older framework versions. You will need to change the profile for your portable class library project so that it targets these frameworks.


Solution:


Option 1:

Target Frameworks
.Net 4.5, Silverlight 5, Windows Phone 8, Windows Store apps (Windows 8)


Option 2:

The workaround mentioned on a comment on Stuart's blog (at http://slodge.blogspot.co.uk/2013/04/n0-first-mvvmcross-application-n1-days.html) worked for me:
Remove Mono for Android, MonoTouch, VS MonoTouch and Windows Phone from the Target Frameworks in the Core project properties. Install MvvmCross NuGet package. Add the Target Frameworks back in.

Tuesday, September 2, 2014

Updating ApplicationBarIconButton Dynamically - Causes NullReference

Problem:

I ran into this error trying to disable a icon on the Application Bar of my Windows Phone Application.  I declared the applicationbar declaratively and not programmatically.  When I went to
access the applicationbar icon I assigned it a name property using x:Name.  The control resolved to
null.


AppBarEmailButton.IsEnabled = true;

Error Message:
System.NullReference: Object Reference not set to an instance of an object.


Solution:

Microsoft.Phone.Shell.ApplicationBarIconButton btn = (ApplicationBarIconButton )ApplicationBar.Buttons[0];

btn.IsEnabled = true;

or declare the applicationbar programmatically.



Source
http://blogs.msdn.com/b/ptorr/archive/2010/06/18/why-are-the-applicationbar-objects-not-frameworkelements.aspx?wa=wsignin1.0

http://stackoverflow.com/questions/5334574/applicationbariconbutton-is-null

http://social.technet.microsoft.com/wiki/contents/articles/975.updating-applicationbariconbutton-dynamically.aspx