Showing posts from 2014

Separator Insets on UITableView in iOS8 - Xamarin.iOS

In iOS7 it was possible to configure the separator insets by setting the separator inset property on the tableview: tableView.SeparatorInsets = new UIEdgeInsets(0, 0, 0, 0) In iOS8 this no longer works and you need to set the LayoutMargins on both the table and the cell remembering to check if the property is supported first to avoid breaking iOS7 if   ( this .T ableView . RespondsToSelector ( new   Selector ( " setLayoutMargins : " )))     this .T ableView . LayoutMargins   =   new   UIEdgeInsets ( 0 ,   0 ,   0 ,   0 ) ; Commonly the cell separator insets are set by overriding WillDisplay public   override   void   WillDisplay ( UITableView   tableView ,   UITableViewCell   cell ,   NSIndexPath   indexPath ) {     if   (c ell . RespondsToSelector ( new   Selector ( " setLayoutMargins : " )))         c ell . LayoutMargins   =   new   UIEdgeInsets ( 0 ,   0 ,   0 ,   0 ) ; } Hopefully this won't change again with iOS9...

A simple Async await call to download a file with Basic Authentication

A simple async await method to download a file using basic authentication. As this is Basic Auth you should only really use it with https:// calls otherwise the username & password will be sent over as plain Base64 string. using System; using System.IO; using System.Net; using System.Net.Http; using System.Threading.Tasks; private static async Task DownloadFileUsingBasicAuth(string url, string saveFileAs, string username, string password) {                HttpClientHandler handler = new HttpClientHandler();       handler.Credentials = new System.Net.NetworkCredential(username, password);       HttpClient httpClient = new HttpClient(handler);       Uri uri = new Uri(url);       HttpResponseMessage responseMessage = await httpClient.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead);       if (responseMessage.StatusCode == HttpStatusCode.OK)       {           using (var fileStream = File.Create(saveFileAs))           {               using (var httpStream = await responseM

Good Dynamics Android Manifest File Basic Template with Xamarin

At  YARG  we develop Enterprise Apps using Xamarin with the Good Technologies GD SDK.  When creating a new Android App this is the basic Manifest file that we use, which includes the basic permissions.   <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="" android:versionCode="1" package="com.mycompany.myapp" android:installLocation="auto" android:versionName="Version 1.0"> <uses-sdk android:minSdkVersion="17" /> <application android:label="MyApp" android:icon="@drawable/icon"> <activity android:name="" android:windowSoftInputMode="adjustPan"></activity> <!-- Main GD Service --> <service android:name="" android:enabled="true" android:exported="false"></service>

.NET Reflector replacement that's free - ILSpy

This is a replacement for .NET Reflector (which has been owned by RedGate since 2011... boooo...) ILSpy requires the .NET Framework 4.0.

Xamarin Forms - InitializeComponent does not exist in the current context

I was presented with this error whilst developing with Xamarin Forms For me it was simply down to copy and paste :-O.  I'd created a new Xaml Page, which fully qualified was MyNameSpace.MyPage. I then copied in some Xaml which had a different name in the Xaml x:Class attribute (x:Class="NotMyNameSpace.OrPage"). I then tried to compile with our fixing the x:Class attribute and got the 'InitializeComponent does not exist' error. Once I changed the Xaml to match my actual classname (x:Class="MyNameSpace.MyPage") I was back on track and the error went away. Hope this helps. For more information have a look at The other reason is that you may have created a Shared Xamarin Forms Project rather than a Xamarin Forms Portable project. From Craig Dunn at Xamarin (taken from  Xamarin Forms Forum ) You cannot use Xaml with the Shared Project template with iOS apps (in Xamarin Studio). It's a weird combination to rem

Xamarin Forms - XamlParseException: No embeddedresources found

When developing with Xamarin Forms you may get the exception below when using Xaml XamlParseException: No embeddedresources found This is a known bug and for now a work around is to save the Xaml file before running/building. Have a look at this for more info:

Xamarin Android - Deployment failed. Assembly synchronization error

When deploying a Xamarin Android App to a device we were getting the error ' Deployment failed. Assembly synchronization error '.  Apparently this happens on Samsung devices with Knox  installed and to get around the problem you can uncheck ' Fast assembly deployment' in Xamarin Studio via the project options, a screenshot is below: The problem here, for us anyway, is that it then removes the existing package and reinstalls a new one every time.  As we're developing Apps using Xamarin bindings for Good Technologies Good Dynamics it then throws up the rather annoying email address / pin screen, as seen in the screen below every time we tried to update and deploy the App. During Good Dynamics development to get round this problem you just have to either use a non Knox/Samsung device or the standard SDK Emulators (as a side note Genymotion won't work with Good due to the lack of 386 support).   Ok it looks like this was a red herrin

iOS AOT errors on device

If your application is running correctly in the iOS simulator but you see AOT errors on the device itself one possible fix is to enable generic value type sharing in the advanced tab of the iOS Build settings in Xamarin Studio. See the Xamarin docs (iOS specific enhancements section) for more details:

Developing Android Apps with Xamarin - Useful Links

Xamarin Docs - Android Resources Android Asset Studio

Useful stuff to help with Xamarin Android Bindings

At  YARG , we have successfully created Xamarin bindings to Good Technology's iOS Good Dynamics SDK and we've now got a few iOS Enterprise Apps out there in the field.  We're now in the process of creating the Android binding set, we're not far off but we still have a few interfaces / classes that we need to expose.  As a point of reference on some of the toolsets we're using I thought I'd jot them down here. When you're binding against a .jar file it's very handy to traverse the package to see what classes, types etc are exposed. To do this, you have a few options (of course there are more but these work for us and they're free) Extracting the Contents of a JAR File  which is the standard command line operation on a Mac OSX On Windows development boxes we use this excellent free tool JD-GUI is a standalone graphical utility that displays Java source codes of “.class” files When you are trying to create your Xamarin Android bindings you

Backgrounding with Xamarin and other useful links

Backgrounding  Backgrounding with Tasks iOS Backgrounding Guidance e/ Android Network Discovery Compiling for Different Devices Memory and Performance Best Practices Techniques for Building Efficient Xamarin Applications  App Store Submission Tips

Useful Xamarin .NET PCL Links

Cross-Platform Development with the Portable Class Library Azure Mobile Services Portable Class Libraries (PCL) Portable Class Libraries (PCL) - Raw low level Universal Apps: What Are They And Can I Use Them With Xamarin? Other

iOS Cannot install applications because the certificate is not valid

When you upgrade to iOS 7.1 and try to distribute an App via your own means, say for Enterprise distribution, you may get the following error when you try and download the plist. 'Cannot install applications because the certificate for <hostname> is not valid' It turns out that App have changed the rules with 7.1, the plist file must be behind a certificate. So instead of it will need to be This is a real pain if you're a small outfit as you'll have to purchase a SLL certificate. One option is to use Azure as you'll get a default SSL that you can use. Remember if you're rolling your own distribution you will need to make sure your web server, i.e. IIS, understands the mime types .ipa and .plist

System.UnauthorizedAccessException error with Visual Studio and Xamarin

When you try and install Mono.Android in Visual Studio for the first time you may find that you're presented with an error similar to the one below: System.UnauthorizedAccessException: Access to the path 'C:\ProgramData\Mono for Android\License' is denied. at Xamarin.Components.Ide.Activation.ActivationService.GetErrorWorkflow(LicenseSyncResult[] results, Boolean ignoreSyncErrors) at Xamarin.Components.Ide.Activation.ActivationService.<GenerateFullWorkflowSequence>d__88.MoveNext() at Xamarin.Components.Ide.Activation.ActivationDialog.DisplayWorkflowStep(ActivationWorkflowStep step) at Xamarin.Components.Ide.Activation.ActivationDialog.<>c__DisplayClass13.<StartSpinnerTaskAndScheduleContinuation>b__12(Task t) If you close down VS and run it again as an Administrator it should sort the issue out. Remember activation of your Xamarin licenses doesn't actually kick off until you run the project for the first time. If you're still having activat

When using Apple iOS APNS (Apple Push Notifications) how can I find which environment the Provisioning Profile is pointing to?

When using the Development Certificate and Profiles you will be using the Development (and Sandbox) setup.  For AdHoc and AppStore you will be using the Production environment. You can check by looking at the Provisioning Profile, just open the file up with a simple editing tool such as TextEdit and look for the key aps-environment, it will be either development or production an example snippet is below: <key>aps-environment</key> <string>production</string> I hope this helps! 

Xamarin Studio - Not built in active configuration

Sometimes when you open up a solution in Xamarin Studio you will may see that one or more of the projects are greyed out with the text 'not built in active configuration' .  This mainly seems to happen when you open up a Visual Studio solution in XS. To check your solution, right click on the solution node and select Options and then under Build click on Configurations.  To the the right you will see two Tabs, click on the 'Configuration Mappings' and you will see the targets for each of your solution projects. This may change in future Xamarin Studio builds (current stable build is 4.2.2)