Quantcast
Channel: Ionic Forum - Latest posts
Viewing all 230429 articles
Browse latest View live

Semantics of the App Plugin using App.addListener("backButton", myCallback)

$
0
0

The the back button does different things, depending on which page is currently showing. For example, in the login page there is a 2-step process: first the user enters the username and presses “Next”, and then the password input shows up. If the user hits the hardware back button then it goes back to the username prompt. It’s just part of the requirements for the mobile app that I’m building. I don’t have the option of using something other than the hardware back button, because that is what is specified.

Having a single back-button callback registered globally when the app loads is going to be tricky. The callback code is going to have to somehow reach in to the Vue.JS components that are currently active and perform complex logic. Doing all that in a global callback means exposing all the inner workings of the various views/pages so they can be manipulated by a global callback. Yuck…


Semantics of the App Plugin using App.addListener("backButton", myCallback)

$
0
0

I see. If you don’t think there is another way, you could use Ionic’s Lifecycle Methods to either register/unregister the listener or just set an active flag and then within your logic, if not active, don’t run the code. Using the Lifecycle methods, Page A shouldn’t have to know about Page B and Page B shouldn’t have to know about Page A.

Activity class {io.ionic.starter/my.domain.organisation.MainActivity} does not exists

$
0
0

I use ionic Framework 7.1.1 with Angular and I use the Studio Code Editor.
With Studio Code Editor I replaced all “io.ionic.starter” appearance with “my.domain.organisation”.
If I run my app with ionic serve than everything works fine.
After I build the android app with

  1. npx cap sync
  2. npm run build
  3. npx ionic capacitor sync android

and than install the app over Android Studio at physical device, I get the following error:

Error running app: Activity class {io.ionic.starter/my.domain.organisation.MainActivity} does not exists in Android Studio.
The strange thing is that the app works fine on physical device.
What can I do in order to solve this error?
Thanks a lot

CSS Variables not defined in ion-modal

$
0
0

Hi all!
I’m creating a modal with ModalController.create and I have some ion-inputs which look weird because they are not consuming the global CSS variables.

I wonder if this is happening only to me, as I see no reason for these elements to not access the :root variables and appear as undefined:

image

Help please :pray:

Activity class {io.ionic.starter/my.domain.organisation.MainActivity} does not exists

Activity class {io.ionic.starter/my.domain.organisation.MainActivity} does not exists

$
0
0

Thanks for your answer!
Yes. I did it at all spots. Maybe It is an Android Studio issue.
Because if I install it on physical device all works fine - maybe I can ignore it - I have no idea of this issue.

Activity class {io.ionic.starter/my.domain.organisation.MainActivity} does not exists

Ionic X - Alternatives

$
0
0

Actually, the only strong alternative to Ionic X is Appery.io. It’s a no-code and low-code app builder based on the Ionic framework. Appery.io offers a similar drag-and-drop approach as Ionic X, allowing you to create app logic with or without writing code, depending on your preference.


Trying to Get Capacitor Working in Vanilla JS Ionic Project

$
0
0

I am in the process of migrating an SPA started several years ago using Onsen UI and Cordova to a vanilla JavaScript Ionic project using Capacitor. I’ve successfully ported most of the existing functionality over, and am just starting to explore adding native functionality using Capacitor. I am struggling mightily and unable to get anything to work. I haven’t worked with the new module syntax previously, and am not sure what I’m doing wrong. I also haven’t previously worked with Webpack.

Here’s some specifics on my development environment:

  • I’m working on an M1 Mac running Sonoma
  • Node version is 20.17.0
  • Ionic is 7.2.0
  • Capacitor version is 6.1.2

I initially tried adding the Ionic Storage plugin, and managed to get my init() function to create a Store object. But when I try adding the Camera plugin to the project, I get the following error message:

Uncaught TypeError: The specifier “@ionic/storage” was a bare specifier, but was not remapped to anything. Relative module specifiers must start with “./”, “…/” or “/”.

Any pointers to get me moving in the right direction would be greatly appreciated. Here is my index.js file:

import { Storage } from "@ionic/storage";
import { Camera, CameraResultType, CameraSource } from "@capacitor/camera";
import { defineCustomElements } from "@ionic/pwa-elements/loader";

defineCustomElements(window);

async function initStorage() {
	const store = new Storage();
	await store.create();
	console.log("Ionic Storage is ready");

	// Assign store to the global window object for access in the console
	window.store = store;
}

initStorage();

export async function takePhoto() {
	const image = await Camera.getPhoto({
		quality: 90,
		allowEditing: false,
		resultType: CameraResultType.Uri,
		source: CameraSource.Camera,
	});

	console.log("Photo URL:", image.webPath);
}

Here is package.json:

{
	"name": "pageone-inspection",
	"version": "0.0.1",
	"dependencies": {
		"@capacitor/android": "^6.1.2",
		"@capacitor/app": "6.0.1",
		"@capacitor/camera": "^6.0.2",
		"@capacitor/core": "6.1.2",
		"@capacitor/haptics": "6.0.1",
		"@capacitor/ios": "^6.1.2",
		"@capacitor/keyboard": "6.0.2",
		"@capacitor/status-bar": "6.0.1",
		"@ionic/core": "^8.2.7",
		"@ionic/pwa-elements": "^3.3.0",
		"@ionic/storage": "^4.0.0"
	},
	"devDependencies": {
		"@babel/core": "^7.25.2",
		"@babel/preset-env": "^7.25.4",
		"@capacitor/cli": "6.1.2",
		"babel-loader": "^9.2.1",
		"html-webpack-plugin": "^5.6.0",
		"webpack": "^5.95.0",
		"webpack-cli": "^5.1.4",
		"webpack-dev-server": "^5.1.0"
	},
	"scripts": {
		"start": "webpack serve --config webpack.config.js",
		"ionic:build": "webpack --config webpack.config.js",
		"ionic:serve": "webpack serve --config webpack.config.js"
	},
	"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}

And here is webpack.config.js:

const HtmlWebpackPlugin = require("html-webpack-plugin");
const path = require("path");

module.exports = {
	entry: path.resolve(__dirname, "www/js/index.js"),
	output: {
		filename: "bundle.js", // Output bundle file
		path: path.resolve(__dirname, "www/dist"),
	},
	devServer: {
		static: path.join(__dirname, "www"),
		port: 8080,
	},
	plugins: [
		new HtmlWebpackPlugin({
			template: "./www/index.html",
		}),
	],
	module: {
		rules: [
			{
				test: /\.js$/,
				exclude: /node_modules/,
				use: {
					loader: "babel-loader",
					options: {
						presets: ["@babel/preset-env"],
					},
				},
			},
		],
	},
	resolve: {
		modules: [path.resolve(__dirname, "node_modules")],
		alias: {
			"@capacitor": path.resolve(__dirname, "node_modules/@capacitor"),
			"@capacitor/camera": path.resolve(__dirname, "node_modules/@capacitor/camera/dist/index.js"),
		},
		fallback: {
			"@capacitor/camera": false,
		},
	},
	mode: "development",
	cache: false,
};

My project directory structure is organized as follows:

  • Project root
    • package.json
    • webpack.config.js
    • android
    • ios
    • node_modules
      • @capacitor
      • @ionic
    • www
      • css
      • dist
        • bundle.js
      • js
        • index.js
      • css
        • main.css
      • index.html

I’m happy to provide any other files or details that would be helpful. Thanks to anyone for taking a look~

Passing larger plugin call (10MB) freezes UI

$
0
0

We do have an issue in our app. We would like to send some data from JS to our native side. We use plugin calls for that. We don’t await the results on the JS side, we don’t run blocking code on the native side, however, the UI freezes for around 1-3s.

We are assuming the bridge, messagehandler or something along these lines run code on the UI thread.

Is this known? Is there anything we can do?

Ion-input-password-toggle not showing placeholder for input

$
0
0

As the title says, ion-input-password-toggle does not show the placeholder for the associated input. Here is an example of the code:

<ion-input label="Password" type="password" label-placement="floating" fill="outline" formControlName="password" placeholder="Password" class="input-radius ion-margin-bottom">
    <ion-input-password-toggle slot="end"></ion-input-password-toggle>
</ion-input>

Ion-input-password-toggle not showing placeholder for input

$
0
0

Looks like this is a bug with Ionic. From my testing, the label is always floating and the placeholder only shows when you click into the input box. The placeholder only showing when clicking into the input box is normal behavior for a floating label.

I found two related open issues for this:

Ignore external imports on build if they are not found

$
0
0

I second this question

Any help?

Controls always showing "Ionic app" while playing

$
0
0

Hi,

I’m trying to show some music controls using the MediaSession API. It’s works almost (Mac OS controls bar, Google Chrome) everywhere except on iOS device which is always displaying “Ionic App” while playing. I’m testing this on my real Iphone. The code which I’m using seems to have some effects because while I’m using it, previous and next buttons appears.

Capture d’écran 2024-10-07 à 20.34.15

Here’s my background modes config :

Capture d’écran 2024-10-07 à 20.32.56

Here’s my code

import React, { useEffect, useRef, useState } from 'react';
import { IonButton, IonItem, IonLabel } from '@ionic/react';

const MediaPlayer: React.FC = () => {
  const audioRef = useRef<HTMLAudioElement | null>(null);
  const [isPlaying, setIsPlaying] = useState(false);

  // Fonction pour démarrer la lecture de l'audio
  const playAudio = () => {
    if (audioRef.current) {
      audioRef.current.play().then(() => {
        // Mettre à jour les métadonnées après le début de la lecture
        if ('mediaSession' in navigator) {
          navigator.mediaSession.metadata = new MediaMetadata({
            title: 'Track',
            artist: 'Artist',
            album: 'Album'
          });
        }
      });
      setIsPlaying(true);
    }
  };

  // Fonction pour mettre en pause l'audio
  const pauseAudio = () => {
    if (audioRef.current) {
      audioRef.current.pause();
      setIsPlaying(false);
    }
  };

  // Utilisation de l'API Media Session
  useEffect(() => {
    console.log('Initialisation de l\'API Media Session');
    if ('mediaSession' in navigator) {
      navigator.mediaSession.setActionHandler('play', () => {
        playAudio();
      });

      navigator.mediaSession.setActionHandler('pause', () => {
        pauseAudio();
      });
    }
  }, []);

  return (
    <IonItem>
      <IonLabel>Lecteur Audio</IonLabel>
      <audio ref={audioRef} src="/files/pwop.mp3" preload="metadata" />
      {isPlaying ? (
        <IonButton onClick={pauseAudio}>Pause</IonButton>
      ) : (
        <IonButton onClick={playAudio}>Play</IonButton>
      )}
    </IonItem>
  );
};

export default MediaPlayer;

Did you know how I can achieve this please ? Thanks you very much !

Controls always showing "Ionic app" while playing

$
0
0

Some quick Googling I came across this SO that points to a a fluke in iOS where in a PWA it will sometimes show the title of the web page instead of what was set in the metadata.

Assuming you’ve verified setting the metadata is actually getting called on the iOS device?

Before you go down the road of an HTML audio player, are you planning on supporting Android too? If so, metadata for WebView Android is not supported. You also won’t be able to support background play on Android as you need to use a foreground service.

You might want to check out the Capacitor audio plugin I created - GitHub - mediagrid/capacitor-native-audio: Play audio in a Capacitor app natively from a URL/web source simultaneously with background audio and background play support.


Is it possible to connect a React Capacitor Android App to Google Tag Manager?

$
0
0

Hi! Im looking to use GTM on my ionic + capacitor project.
Is the implementation of GTM straight forward? Or you have to do something special like install a specific package for the ionic and capacitor ?

Thanks in advance!

Controls always showing "Ionic app" while playing

$
0
0

Hi,

Thank you for your quick response! During my research, I discovered your plugin but I must admit that I have a little difficulty implementing it as a component of my application. Do you have a code example of a component using your plugin so that I can re-adapt mine?

Thanking you very much.

Controls always showing "Ionic app" while playing

Blank page issue after splash in iOS 18

Ion-datetime wheel not draggable in browser mode

$
0
0

I’m guessing there is no solution for this. Its not very usable in the browser.
I have tried using [preferWheel]=“false” for the browser but month and year are always wheel selection.

I have changed to use the below for desktop as the Ionic datetime picker is not really usable.

<mat-form-field>
  <mat-label>Choose a date</mat-label>
  <input matInput [matDatepicker]="picker">
  <mat-hint>MM/DD/YYYY</mat-hint>
  <mat-datepicker-toggle matIconSuffix [for]="picker"></mat-datepicker-toggle>
  <mat-datepicker #picker></mat-datepicker>
</mat-form-field>
Viewing all 230429 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>