Bug 23878 - Percent-encoding (URI) don't work in iOS
Summary: Percent-encoding (URI) don't work in iOS
Status: RESOLVED DUPLICATE of bug 29247
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.2.3
Hardware: PC Windows
: Normal critical
Target Milestone: ---
Assignee: Jason Smith [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2014-10-16 12:40 UTC by Fredy Wenger
Modified: 2015-07-22 09:40 UTC (History)
11 users (show)

Tags: ac ios crash webview RA
Is this bug a regression?: ---
Last known good build:


Attachments
Device Open Uri Exception Recreation (50 bytes, text/plain)
2015-04-20 13:38 UTC, Nick Spiers
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED DUPLICATE of bug 29247

Description Fredy Wenger 2014-10-16 12:40:12 UTC
Xamarin.Forms, version-information see at end of message:

I have implemented googlemaps in my app with:
Device.OpenUri(new Uri("http://maps.google.com/?daddr=" + cURL_Ziel_Android));

where cURI_Ziel_Android contains the street-address to show.

As the app will be used in Switzerland and the addresses will be dynamic, I have to use “percent-encoding” for all special characters like à,é,è, è, etc. and remove spaces.

Therefore, I have built a function (pass string with special characters (like “Höhenweg 9”) and giv-back a “percent-encoded” string (like”H%c3%b6henweg+9).

This works fine on Android and WP, but not on iOS:-(.
As soon, as I have a %-Char in the URI, the App crashes hard on iOS (while I run’s on Android an WP) .

Unhandled Exception:
System.Exception: Could not initialize an instance of the type 'MonoTouch.Foundation.NSUrl': the native 'initWithString:' method returned nil. It is possible to ignore this condition by setting MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure to false.

Command-Line:
Device.OpenUri(new Uri("http://maps.google.com/?daddr=" + cURI_Ziel_Android));

Content cURI_Ziel_Android:
"H%c3%b6henweg+9+8966+Oberwil-Lieli+Schweiz"

Command with whole string: 
Device.OpenUri(new Uri("http://maps.google.com/?daddr=H%c3%b6henweg+9+8966+Oberwil-Lieli+Schweiz"));


Version information's:
Microsoft Visual Studio Professional 2013
Version 12.0.30501.00 Update 2
Microsoft .NET Framework
Version 4.5.51641

Installierte Version: Professional

LightSwitch für Visual Studio 2013   06177-004-0446016-02937
Microsoft LightSwitch für Visual Studio 2013

Office Developer Tools - Mai 2014 Update DEU   06177-004-0446016-02937
Microsoft Office Developer Tools für Visual Studio 2013 - Mai 2014 Update DEU

Rechtschreibprüfung für die Visual Studio 2013-Codeanalyse   06177-004-0446016-02937
Rechtschreibprüfung für die Microsoft® Visual Studio® 2013-Codeanalyse

Teile des International CorrectSpell™-Rechtschreibprüfungssystems © 1993 von Lernout & Hauspie Speech Products N.V. Alle Rechte vorbehalten.

The American Heritage® Dictionary of the English Language, Third Edition Copyright © 1992 Houghton Mifflin Company. Elektronische Version lizenziert von Lernout & Hauspie Speech Products N.V. Alle Rechte vorbehalten.

Team Explorer für Visual Studio 2013   06177-004-0446016-02937
Microsoft Team Explorer für Visual Studio 2013

Visual Basic 2013   06177-004-0446016-02937
Microsoft Visual Basic 2013

Visual C# 2013   06177-004-0446016-02937
Microsoft Visual C# 2013

Visual C++ 2013   06177-004-0446016-02937
Microsoft Visual C++ 2013

Visual F# 2013   06177-004-0446016-02937
Microsoft Visual F# 2013

Windows Phone SDK 8.0 - DEU   06177-004-0446016-02937
Windows Phone SDK 8.0 - DEU

Allgemeine Azure-Tools   1.1
Bietet allgemeine Dienste für die Verwendung durch Azure Mobile Services und Windows Azure Tools.

ASP.NET und Webtools   2013.2.50425
Microsoft Web Developer Tools enthält die folgenden Komponenten:
Unterstützung beim Erstellen und Öffnen von ASP.NET-Webprojekten
Browserlink: Ein Kommunikationskanal zwischen Visual Studio und Browsern
Editor-Erweiterungen für HTML, CSS und JavaScript
Seitenprüfung: Prüfungstool für ASP.NET-Webprojekte
Gerüstbau: Ein Framework zum Erstellen und Ausführen von Codegeneratoren
Server Explorer-Erweiterungen für Windows Azure-Websites
Webpublishing: Erweiterungen zum Veröffentlichen von ASP.NET-Webprojekten für Hostinganbieter, lokale Server oder Windows Azure

ASP.NET Web Frameworks and Tools 2012.2   4.1.21001.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.1.20409.0
For additional information, visit http://www.asp.net/

Gizmox Visual WebGui   7.1
Gizmox Visual WebGui Version 7.1

Microsoft Advertising SDK for Windows Phone   
Microsoft Advertising SDK for Windows Phone
Build 

NuGet-Paket-Manager   2.8.50313.46
NuGet-Paket-Manager in Visual Studio. Weitere Informationen zu NuGet finden Sie unter "http://docs.nuget.org/".

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio-Erweiterung zur Visualisierung aggregierter Zusammenfassungen vom PreEmptive Analytics-Produkt.

SQL Server Data Tools   12.0.30919.1
Microsoft SQL Server Data Tools

Windows Azure Mobile Services Tools   1.1
Windows Azure Mobile Services Tools

Windows Phone 8.1 SDK-Integration   1.0
Dieses Paket integriert die Tools für das Windows Phone 8.1 SDK in die Menüs und Steuerelemente von Visual Studio.

Workflow Manager Tools 1.0   1.0
Dieses Paket enthält die erforderlichen Visual Studio-Integrationskomponenten für Workflow Manager.

Xamarin   3.7.203.0 (ff146f5240189a2ec6d3c6f75cf3967f79c79a18)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   4.18.0.34 (3b7ef0a796e8744972c48034403a6e7cb7ec189e)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   8.2.0.0 (65b2f3a0f52f365b90ac952f0ec2e40fa0b510d4)
Visual Studio extension to enable development for Xamarin.iOS.

AddInRessourcen_Vs2013
Erstellt von F. Wenger / 12.2013 für VS2013
Copyright (c) 2013 Matrix Solutions AG
Comment 1 Parmendra Kumar 2014-10-17 10:49:48 UTC
I have checked this issue but I am not able to reproduce this issue, To reproduce this issue I have Download a sample project on github (https://github.com/xamarin/xamarin-forms-samples) and open the WorkingWithMap sample. I have followed steps mentioned in the bug description.
Could you Please provide us sample project that can be helpful to reproduce this issue at my end.

Environment Info:
Microsoft Visual Studio Professional 2013
Version 12.0.30723.00 Update 3
Microsoft .NET Framework
Version 4.5.51641

Installed Version: Professional

Xamarin   3.7.203.0 (ff146f5240189a2ec6d3c6f75cf3967f79c79a18)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   4.18.0.34 (3b7ef0a796e8744972c48034403a6e7cb7ec189e)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   8.2.0.0 (65b2f3a0f52f365b90ac952f0ec2e40fa0b510d4)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 2 Fredy Wenger 2014-10-17 11:41:30 UTC
Do you have tried 1:1:

Device.OpenUri(new
Uri("http://maps.google.com/?daddr=H%c3%b6henweg+9+8966+Oberwil-Lieli+Schweiz"));

Simply copy-paste the line above in your test-page (in an button click-handler)
This works in your Test-iOS-App???
Comment 3 Parmendra Kumar 2014-10-20 09:53:11 UTC
I have checked this issue as per comment 2 but I am not able to reproduce this issue.Please check the Screencast and sample project in gist and let me know if I missed anything. Could you please provide us sample project that can be helpful to reproduce this issue at my end.

Screencast:http://www.screencast.com/t/9QAkgcEjz

Sample page:https://gist.github.com/Parmendrak/2e40f1af7941fc36c88f
Comment 4 Fredy Wenger 2014-10-20 12:29:56 UTC
Please test your example on a REAL iPhone5
Comment 5 Parmendra Kumar 2014-11-05 13:28:47 UTC
I have tried to reproduce this issue on latest stable Xamarin builds with iOS
device iPhone 5s(iOS 7.1) but I am still not able to reproduce this issue.

If you are still able to reproduce this issue with latest stable Xamarin builds
then please include following piece of info.

1. Mtb server log - via Mac-Xamarin.iOS Build Host->View Build Host Log
2. iOS device log - from Xcode(Symbolicated Logs) 
3. Zip Xamarin logs - VS-Help-Zip Xamarin Log

We may have to see if a developer can figure out what's going on from the above piece of info.

Environment Info:
Windows 8.1
VS 2013, XVS 3.7.248.0

Mac Build host:
Xcode-6.1(6602)
XiOS- 8.4.0.16 (Business Edition)
Comment 8 Fredy Wenger 2015-01-21 03:24:09 UTC
@Russel Fustino:
Thanks for reporting - so I know, I am "not alone in the dark".
For your Information:
As workaroud, I have (had to) wrote an function that changes the special characters in the url for iOS (e.g. ä = ae, ü = ue, etc.)
Comment 10 Russell Fustino 2015-01-22 21:07:13 UTC
I have another work around... the Webview Control. The same URL that caused the native browser to crash the app, works when rendered thru a webview control. Interesting, huh? I am using a webview renderer as well.
Comment 11 Nick Spiers 2015-04-20 13:38:01 UTC
Created attachment 10824 [details]
Device Open Uri Exception Recreation
Comment 12 Nick Spiers 2015-04-20 13:40:45 UTC
The attached project demonstrates Device.OpenUri bombing when there are url parameters.
Comment 14 Sami M. Kallio 2015-04-30 17:42:56 UTC
This should be an easy fix on Forms by replacing uri.ToString() with this:

    var url = NSUrl.FromString(uri.ToString()) ?? new NSUrl(uri.Scheme, uri.Host, uri.LocalPath);

I tested this method with Uri's that contain spaces. The uri.ToString() method with NSUrl.FromString will return null in this case. Using the constructor with the uri pieces will successfully create a NSUrl with %20 inserted.
Comment 15 Seth Rosetter 2015-06-05 14:29:38 UTC
This issue has been fixed and will be included in 1.4.3 final. 

Thanks for taking the time to file this and for providing a concise reproduction.

- Seth
Comment 16 John Hardman 2015-07-15 07:02:49 UTC
Note that even in 1.4.3.6376, using WebView, if the URL has a trailing space, this same error occurs.

Message	"Could not initialize an instance of the type 'Foundation.NSUrl': the native 'initWithString:' method…"	string
Source	"mscorlib"	string
StackTrace	"  at Foundation.NSObject.InitializeHandle (IntPtr handle, System.String initSelector) [0x000b0] in /…"	string

Obviously, the solution is to ensure there are no trailing spaces :-)
Comment 17 Stephane Delcroix 2015-07-22 09:40:47 UTC

*** This bug has been marked as a duplicate of bug 29247 ***