Ionic Geolocation Permission issue on iOS - ios

I have a problem with the GeoLocation Plugin at ionic3.
I added all the import stuff. The <edit-config> part too. I can see this in my plist file:
<key>NSLocationWhenInUseUsageDescription</key>
<string>Get Position</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Get position</string>
So I think it works. But it doesn't; it works for Android but not for iOS.
I call this method:
this.geolocation.getCurrentPosition().then((resp) => {
alert("geo " + resp.coords.latitude);
// resp.coords.latitude
// resp.coords.longitude
}).catch((error) => {
alert(error.code);
alert(error.message);
});
I got the Error.code 2 and the Error.message: "Origin does not have permission to use Geolocation service".
What should I do?

I had this exact problem -- I had to manually add this privacy setting in the *.plist file in XCode itself (found in resources/).
Under Key you type Privacy - Location When In Use Usage Description, or at least start typing it, and it will autocomplete. Type should be String and Value should be the message you want to popup to the user explaining why you need access to location data.

I had the same problem. I used Ionic v4 with React, Cordova v9, cordova-ios v4.5.5. The problem in my case happened because I didn't inject the Cordova JS script to the webview. To fix it, I added the following Bash script to Cordova's before prepare hooks ((cordova root)/hooks/before_prepare/inject_cordova.js):
#!/bin/bash
set -e
sed -E -i "" -e "s_(<head[^>]*>)_\1<script src=\"cordova.js\"></script>_" www/index.html
Where www/index.html is the path to your application main HTML file relative to the cordova project root.
The last line adds a <script src="cordova.js"></script> tag to the end of the HTML file when you run cordova prepare ios. As a result, the webview starts loading the Cordova scripts including the geolocation plugin and the application starts asking a permission to use the geolocation.

Related

How to use "window.open" in iOS for js command?

I am using Appery.io app builder and my app is JQM with v5.3 libraires version
I have to js code in click event and run in Android but not in iOS.
I tried this and the same result. Anything argument in window.open run in Andorid but not in IOS (mail, https…).
window.open("tel:+34607507097");
window.location.href = 'tel:+34607507097';
Any suggestions . Thanks
Could I ask you to check if the in-app browser is enabled under App settings > Cordova Plugins and then check out this code:
if (window.cordova) {
cordova.InAppBrowser.open("tel:+34607507097", '_system');
}

How to save file with Capacitor on iOS?

I have the following code (adapted from this tutorial) that I use for saving files from backend:
import { FilesystemDirectory, Plugins } from '#capacitor/core';
const { Filesystem } = Plugins;
await Filesystem.writeFile({
path: "filename.txt",
data: "base64 data",
directory: FilesystemDirectory.Documents,
});
This codes works fine on Android, even creates the Documents directory in the root of internal storage. Unfortunately, on iOS no file is created, no mater what directory I use (I've tested it with Documents, Data and ExternalStorage).
When I put this code block inside try..catch, nothing is thrown, so the operation is supposedly completed successfully, just no file is saved. Tested on one Android device and two iOS.
iOS doesn't allow accessing file storage directly. I made it work with Ionic-native's FileOpener like this:
import { FileOpener } from '#ionic-native/file-opener/ngx';
import { FilesystemDirectory, Plugins } from '#capacitor/core';
const { Filesystem } = Plugins;
const result = await Filesystem.writeFile({
path: "filename.txt",
data: "base64 data",
directory: FilesystemDirectory.Documents,
});
this.fileOpener.showOpenWithDialog(result.uri, 'application/json')
It opens a dialog where you can select where to save your file. It's a bit confusing as the function's description is "Opens with system modal to open file with an already installed app" but saving works with it as well.
You need to also install cordova-plugin-file-opener2 and put ionic FileOpener to providers in app.module.ts. If you are not using Cordova otherwise, you don't need to do Cordova setups, it works alongside Capacitor as a separate plugin. As far as I'm aware, Capacitor doesn't provide a solution for downloading in iOS.
I've encountered the same problem (while having capacitor 4.2.0 only) and solved it by adding the following permissions in my Info.plist:
<key>UIFileSharingEnabled</key>
<string>YES</string>
<key>LSSupportsOpeningDocumentsInPlace</key>
<string>YES</string>
After this, using directory Directory.Documents has made me visible a Documents directory with the name of the app under the Files App.
Hope it helps.

How to debug electron production binaries

I can't open devtools in the built version of my electron app. Therefore i want to find another solution to log any errors that only occur in the production version.
Is there any good way to get some console.logs from an electron application if its already built?
Obviously i can debug the “development” version (running npm run dev) of my electron app by opening the chrome dev tools. But i can’t find any way to enable them inside my production application.
I am using the newsest version of electron-vue
Thanks for any help in advance.
Here's what worked for me on Mac.
In terminal type lldb path/to/build.app
In the opened debugger type run --remote-debugging-port=8315. It should open a window of your app.
Open Chrome at http://localhost:8315/
Click on the name of the app. For example, Webpack App.
If you don't see anything in the opened tab, focus on the window of your app.
Launch your Electron application with the --remote-debugging-port=8315 flag set and navigate to chrome://inspect/#devices in Chrome 80+. Then click Configure... and add localhost:8315 as a discovery server.
Then, wait for your Electron instance to appear in the devices list and click inspect.
Enabling the Chrome devtools in production can be done in various ways:
A environment variable:
E.g. under Windows set ELECTRON_ENV=development&& myapp.exe
Pass a special parameter to your app
E.g. myapp.exe --debug
Debug mode via user settings (if you have persistent settings)
Menu entry to open the devtools
Can be combined with 1.-3. to only have that menu entry when in debug mode
You can just check if 1.-3. are set and if they are, you simply open the devtools via mainWindow.webContents.openDevTools()
Personally I use a combination of 1., 3. and 4. I simply unlock a developer menu that allows me to open the devtools or opens the userdata folder for me.
If you also want to log critical errors, then electron-log looks like a rather popular option for electron.
On Mac just run open /Applications/WhatsApp.app --args --remote-debugging-port=8315 and then open http://localhost:8315
https://github.com/bytedance/debugtron
Debugtron is an app to debug in-production Electron based app. It is also built with Electron.
The way to do this is using the --remote-debugging-port flag.
Using Signal as an example, take the following steps:
start the application from the CLI
signal-desktop --remote-debugging-port
Open the debugging URL in a Google Chrome browser (in this case http://localhost:39733/), this will open a page with the app name on it .
Click the to open a screen were you can click around to use the app and see output in the devtools
Alternatively, you can open chrome://inspect/#devices in the Google Chrome browser and click "inspect" (underneath the app name) to open the same window
In my case, I had a runtime error crashing Electron before the web view was even shown. Chrome dev tools were not useful for debugging this kind of error.
Even stranger, the app loaded fine using the lldb commands:
lldb ./dist/mac/electron-quick-start-typescript.app
run --remote-debugging-port=8315
I managed to solve by writing the Node.js console log/error to a file. So I could see the console output:
import fs from 'fs';
import util from 'util';
// use a fixed path, to ensure log shows outside Electron dist
const logPath = `/Users/username/Sites/electron-server/debug-${isDev ? 'dev' : 'prod'}.log`;
const logFile = fs.createWriteStream(logPath, { flags: 'w' });
const logStdout = process.stdout;
console.log = function(...args) {
logFile.write(util.format.apply(null, args) + '\n');
logStdout.write(util.format.apply(null, args) + '\n');
}
console.error = console.log;
I found the error was a relative path issue. When the app is started in production mode the relative path did not point to the correct location.
I solved by using an absolute path, with Electron getAppPath() method:
- './renderer'
+ app.getAppPath() + '/renderer'
In the main/index.js at the end of section app.on('ready') just add:
mainWindow.webContents.openDevTools();
Just for debugging, when electron opens an empty window, but the development version works fine, this way is very helpful for me.
The answers above don't help for me. ( those with -remote-debugging-port)
put this code into your main.js or similar file, it will automatically open the dev-tool when started.
mainWindow.webContents.openDevTools()
June 2022 UPDATE:
Devtools can be explicitly enabled through on the BrowserWindow object.
mainWindow = new BrowserWindows({
...,
webPreferences: {
...,
devTools: true,
}
}
And then you can manually open it on load.
mainWindow.on('ready-to-show', () => {
if (!mainWindow) {
throw new Error('mainWindow is not defined')
}
mainWindow.show()
mainWindow.webContents.openDevTools()
})

Ionic unable to load App ID or API Key

I have an existing app that I am trying to add push notifications to. After following through Ionic's own tutorials on adding it, I'm stuck with the app reporting:
CORE: Unable to load app ID or API key, falling back to $ionicApp.getApp()...
I've been Googling around trying to find an answer with no luck. In the main app.js I have added ionic.service.core, ngCordova, and ionic.service.push, as well as the config code block with the ids filled in:
.config(['$ionicAppProvider', function($ionicAppProvider) {
$ionicAppProvider.identify({
app_id: 'APP_ID',
api_key: 'API_KEY'
});
}])
In index.html I have added all the needed resources, particularly:
<script src="lib/ionic-service-core/ionic-core.js"></script>
<script src="lib/ionic-service-push/ionic-push.js"></script>
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
I have run ionic config build, ionic prepare ios, ionic build ios, ionic config set dev_push true repeatedly with no luck.
What am I missing?

distriqt nativemaps- Error w AIR 16

When debugging USB using Apache Flex Compiled SDK - 14.16.16 I get the following error:
Error occurred while packaging the application:
ld: can't open -non_global_symbols_no_strip_list file:
/Users/CRMantra/AIR_14.16.16/lib/aot/lib/local_nostrip.arm-air.txt
Compilation failed while executing : ld64
__________ Found this relating to the platform.xml used in compiling the ANE. https://forums.adobe.com/thread/1220219
I have two questions:
1) I need the permissions for the Maps to throw a NativeDialog box using the requestLocationAuthorization(true) - so User will set permission normally.
2) Whats the recommended and tested SDK version for this ANE. Also, have you been able to set permissions via a Dialog Box from tested SDK? From my reading AIR 16 is the recommended version to set permissions and get around the Geo Object always muted issue. I did notice that NativeApplication.nativeApplication.executeInBackground = true; will fix the Geo.mute issue as well, but it still needs the above mentioned Native Dialog Box, and it requires user to set Privacy/Maps each run of the .ipa
Thanks,
B
I found if you copy the SDK to another location and dereference any symbolic links that the issue disappears.
i.e.
cp -RLf /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk SOME_OTHER_LOCATION

Resources