Flutter url_launcher line break doesn't work in iOS mail program - ios

I'm trying to use the Flutter url_launcher package to create a feedback form template. It worked well so far but I recently did a major package versioning upgrade and now it seems like something is going wrong in the translation of the placeholders.
final Uri _emailLaunchUri = Uri(
scheme: 'mailto',
path: recipient,
queryParameters: {
'subject': subject,
'body': body,
},
);
var newurl = _emailLaunchUri.toString();
return newurl;
The upper is my chunk of code to generate the uri and eventually return the new launch url including some Device information. Printing it out leads to the following output in the console:
mailto:support#support.de?subject=Feedback%3A+App+Name%28Subtitle%29&body=Dear+developers%2C%0D%0A%0D%0AiOS+version%3A+14.6%0D%0Amodel%3A+iPhone11%2C8%0D%0A
So far so good I guess, but that's how it ends up to look in my app (tested on a physical iPhone):
Is there anything I miss or that Apple might have changed in the recent iOS versions? My iPhone is using version 14.6. I figured out to replace the "+" with a %20 instead (seems to be a package error), but I'm not sure how to convert the line breaks correctly.
Would appreciate any help.

Related

Ionic 5 capacitor/angular preview files from external url's

I have tried previewanyfile cordova plugin to open files from external url's in Ionic 5 application. It works well with android but on IOS I noticed sometimes it doesnt preview/open PDF files. Just a grey screen with the file name on it. But strangely some PDF files open.
file preview screen
previewProductDocument(url: string) {
const loading = await this.loadingController.create({
message: 'Loading document...',
});
loading.present().then(() => {
this.previewAnyFile.preview(url).then((res) => {
loading.dismiss();
}).catch((err) => {
loading.dismiss();
this.presentToast('Error previewing the document try later', 'danger');
});
});
}
This is the plugin I have used
https://ionicframework.com/docs/native/preview-any-file
capacitor version "#capacitor/core": "^2.2.0",
Noticed this behavior only in IOS simulator + on Real IOS device.
Any idea what is going on here?
Special character (%2F) in the link is the cause of the issue.
For a quick win; either change the link or sanitise before processing.
In this case url.replace('%2F', '/') should work.
However, another link may, probably, contain a different character. Without being 100% sure, it worth a try decodeURI, which is decodeURI(url).

Slack slash command results in different encoding coming from iOS app or MacOS App

We have a Slash command integration and discovered that the text passed to the slash command is encoded differently if it comes from the (iOS) mobile app compared to the Desktop app.
For the command "/whereis #xsd" on the MacOS Desktop app, the text element in the body is encoded as: text=%3C%23C02MKG1LH%7Cxsd%3E
For the command "/whereis #xsd" on the iOS app the text element in the body is encoded as: text=%26lt%3B%23C02MKG1LH%7Cxsd%26gt%3B
The iOS app is incorrect.
Did anyone else experience this? Any solutions?
(I have posted this question to Slack, they confirmed the behavior a while back but no solution from them so far).
This is not a bug. Both are valid HTML encodings. You can verify this by decoding them on this website.
The difference is that the string from IOS also includes an encoding of HTML special characters (like <) but the desktop string does not. To address this your app has to first do a URL decoding of the input string and then decode special HTML chars.
The results are:
Desktop: <#C02MKG1LH|xsd>
IOS: <#C02MKG1LH|xsd>
Here is a sample code that will decode both strings correctly in PHP:
<?php
function decodeInputString($input)
{
return htmlspecialchars_decode(urldecode($input));
}
$desktop = "%3C%23C02MKG1LH%7Cxsd%3E";
$ios = "%26lt%3B%23C02MKG1LH%7Cxsd%26gt%3B";
$desktop_plain = decodeInputString($desktop);
$ios_plain = decodeInputString($ios);
var_dump($desktop_plain);
var_dump($ios_plain);

How to access image from native URI (assets-library) in Cordova for iOS

I have a Cordova/PhoneGap app which uses the camera to capture a picture. I need to access this picture to send to my server.
For Android I simply use $cordovaFile.readAsDataURL(cordova.file.dataDirectory, fileName)
However; on iOS the filename does not come back as such. My return value for iOS shows the path as
assets-library://asset/asset.JPG?id=539425FE-43AA-48E7-9865-D76348208AC7&ext=JPG
How can I access and read this image? I'd prefer to stick with $cordovaFile but just want to get it to work.
I am using CordovaCameraPreview plugin and the best I can get back from the picture taker handler seems to be something formed similar to:
assets-library://asset/asset.JPG?id=990355E1-200A-4E35-AAA1-7D461E3999C8&ext=JPG
assets-library://asset/asset.JPG?id=C49FF0EB-CCCB-45B2-8577-B13868D8DB29&ext=JPG
How can I convert this to a filename and path that I can read with $cordovaFile? According to their documentation (http://ngcordova.com/docs/plugins/file/) it looks like I need to use one of their paths for File System Layout. It works fine on Android using cordova.file.dataDirectory but can't figure out how to access on iOS
I've also tried using window.resolveLocalFileSystemURL(path) but am getting undefined as my result.
Update
I feel like I'm getting closer... using window.resolveLocalFileSystemURL(path,resolveOnSuccess, resOnError); I get more information
name: "assets-library"
fullPath: "/asset/asset.JPG?id=711B4C9D-97D6-455A-BC43-C73059A5C3E8&ext=JPG"
name: "asset.JPG?id=711B4C9D-97D6-455A-BC43-C73059A5C3E8&ext=JPG"
nativeURL: "assets-library://asset/asset.JPG?id=711B4C9D-97D6-455A-BC43-C73059A5C3E8&ext=JPG"
It looks like I now need to use the fullPath but still can't figure out how to access with $cordovaFile
If I try to use $cordovaFile.readAsDataURL(cordova.file.dataDirectory, data.name) where data.name is asset.JPG?id=711B4C9D-97D6-455A-BC43-C73059A5C3E8&ext=JPG I get a file not found error
Update 2
I have tried using every single File System Layout available at http://ngcordova.com/docs/plugins/file/ and receive the same File Not Found error on each one. Still no clue how to access a file in assets-library using $cordovaFile
I had success with a simple substitution, like this
fullPath = fullPath.replace("assets-library://", "cdvfile://localhost/assets-library/")
It works in iOS 9.3
I was struggling with a similar issue for a while, but I figured it out today. I also thought that the FileSystem APIs didn't work with assets-libary:// URIs -- but that is not the case.
You should be able to get access to the File object (as well as the actual image name) by using the following code:
resolveLocalFileSystemURL('assets-library://asset/asset.JPG?id=711B4C9D-97D6-455A-BC43-C73059A5C3E8&ext=JPG', function(fileEntry) {
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(event) {
console.log(event.target.result.byteLength);
};
console.log('Reading file: ' + file.name);
reader.readAsArrayBuffer(file);
});
});

Use local json file with Cordova/ionic/Angular. Works in browser, but not on device?

I'm attempting to use a JSON object living in a data.json file to be the dataset for a quick prototype I'm working on. This lives in a my_project/www/data/ directory. I have an Angular service that goes and grabs the data within this file using $http, does some stuff to it, and then it's used throughout my app.
I'm using Cordova and Ionic. When using ionic serve on my computer, everything looks perfect in the browser. However, when using ionic view (http://view.ionic.io/) and opening the app on my iPad, I see a:
{"data":null,"status":0,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"../data/items.json","headers":{"Accept":"application/json,test/plain,*/*}},"statusText":""}
for a response. I would think that if it were a relative URL issue, that it would also not work in the browser, but that is not the case.
Here's what I'm doing:
config.xml has this line:
<access origin="*" subdomains="true"/>
My service that preforms the simple request is doing:
return $http.get("../data/data.json").then(function (response) {
return response.data;
});
And finally, in my controller, I ask for the service to preform the request:
myService.goGetData().then(onComplete, onError);
In my browser, onComplete() is invoked and on the iPad, onError() is invoked.
Any guidance?
On your local developer machine you're actually running a webserver when you run ionic serve. So a path like ../../data.json will work because it is totally valid in the context of the webserver that has complete filesystem access.
If, however, you try to do the same thing on your device, you're probably going to run into an issue because the device has security policies in place that don't allow ajax to traverse up outside of the root. It is not a dynamic webserver so it can't load files up the tree. Instead you'd use something like the cordova file plugin to grab the file contents from the filesystem. If you prefer, you can use ngCordova to make interacting with the plugin a bit less painful.
I am 99% sure this is what is happening but you can test my theory by pointing your $http call to some dummy .json data hosted on a publicly available server to see if it works. Here is some dummy json data.
Just gonna leave this here because I had the same problem as the original question author. Simply removing any starting slashes from the json file path in the $http.get function solved this problem for me, now loading the json data works both in the browser emulator and on my android device. The root of the $http call url seems to always be the index.html folder no matter where your controller or service is located. So use a path relative from that folder and it should work. like $http.get("data/data.json")
So this is an example json file. save it as data.json
[
{
"Name" : "Sabba",
"City" : "London",
"Country" : "UK"
},
{
"Name" : "Tom",
"City" : "NY",
"Country" : "USA"
}
]
And this this is what a example controller looks like
var app = angular.module('myApp', ['ionic']);
app.controller('ExhibitionTabCtrl', ['$scope', '$http', function($scope,$http) {
$http.get("your/path/from/index/data.json")
.success(function (response)
{
$scope.names = response;
});
}]);
Then in your template make sure you are you are referencing your controller.
<ion-content class="padding" ng-controller="ExhibitionTabCtrl">
You should then be able to use the a expression to get the data
{{ names }}
Hope this helps :)
I was also looking for this and found this question, since there is no real answer to the problem I kept my search on the Internet and found this answer at the Ionic Forum from ozexpert:
var url = "";
if(ionic.Platform.isAndroid()){
url = "/android_asset/www/";
}
I've used it to load a 3D model and its textures.
update: ionic 2 beta (version date 10 Aug 2016)
You must add prefix to local url like this: prefix + 'your/local/resource'.
prefix by platform:
ios = '../www/'
android = '../www/'
browser = ''
we can create an urlResolver provider to do this job.
notice: only change url in *.ts code to access local resource, don's do this with remote url or in html code.
Have fun and good luck with beta version.
An Starter Ioner
It is possible to access local resources using $http.get.
If the json file is located in www/js/data.json. You can access using
js/data.json
Do not use ../js/data.json. Using that only works in the local browser. Use js/data.json will work on both local browser and iOS device for Cordova.

Firefox Add-on: page mod include pattern won't match

I'm trying to add global hotkey support to Spotify (and others). For this I have to execute a content script in the player app iframe, but no matter what pattern I try Firefox just won't execute my content script.
This is what I try to do:
var data = require("sdk/self").data;
var pageMod = require("sdk/page-mod");
pageMod.PageMod({
include: /^https?:\/\/play\.spotify\.com\/apps\/player\/.+/,
attachTo: ["frame"],
contentScriptFile: [data.url("content.js")]
});
Has anyone any idea what could be wrong? How can I make it match?
See:
https://bitbucket.org/panzi/play-control/src/f1dbd217661c0f09d3615dce7b8b1cab9f8fbf70/browser-plugin/firefox/playcontrol-spotify/lib/main.js?at=default
The same thing for Chrome works perfectly well:
https://bitbucket.org/panzi/play-control/src/f1dbd217661c0f09d3615dce7b8b1cab9f8fbf70/browser-plugin/chrome/playcontrol-spotify/?at=default
I'm a regex noob, but in the doc examples, they don't use ^ even when the string starts with 'http'.
Try getting progressively more stringent to see which part of the regex it doesn't like. Throw an onAttach: console.log("pageMod attached"), in there to make sure it isn't being attached and something else isn't causing the problem.
/.*play\.spotify\.com\/apps\/player.*/ If this works, then either it doesn't like the beginning or the end. Try:
/https?:\/\/play\.spotify\.com\/apps\/player.*/
/^https?:\/\/play\.spotify\.com\/apps\/player.*/
.*play\.spotify\.com\/apps\/player\/.*/
.*play\.spotify\.com\/apps\/player\/.+/
If all of the above work, then your string should work too.
URL matching works the way I've written it. The bug was something else.

Resources