expo-intent-launcher is working fine for Android but not working on ios for expo, and native packages are not installing on expo environment. Is there any solution? Thanks in Advance.
const openFile = (uri, mimeType) => {
FileSystem.getContentUriAsync(uri).then(cUri => {
IntentLauncher.startActivityAsync('android.intent.action.VIEW', {
data: cUri,
flags: 1,
type: mimeType
}).catch(e => {
console.log("Error", e);
alert('No Viewer Found for the file');
})
})
}
The plugin expo-intent-launcher which you are using is currently no equivalent to the iOS platform.
Please read the document carefully.
https://docs.expo.dev/versions/latest/sdk/intent-launcher
https://www.npmjs.com/package/expo-intent-launcher
According to the document as well says to configure for iOS platform "this package does not make sense on iOS as there is no equivalent API, so it is not supported".
Furthermore in the iOS platform you can go with Linking API from react-native libraries.
As an example for opening Bluetooth screen the code looks like,
import {Linking } from 'react-native'
Linking.openURL('App-Prefs:Bluetooth')
Either you can use one of these options given below
First:
You can use from "react-native-webview" library (https://github.com/react-native-webview/react-native-webview)
As an example,
<WebView originWhitelist={['*']} source={{uri: uri}} url can be a web link or path to your file local ('file:///...')
Second:
You can go with the react-native-pdf library.
https://www.npmjs.com/package/react-native-pdf
For example,
import Pdf from 'react-native-pdf';
<Pdf
source={source}
onLoadComplete={(numberOfPages,filePath) => {
console.log(`Number of pages: ${numberOfPages}`);
}}
onPageChanged={(page,numberOfPages) => {
console.log(`Current page: ${page}`);
}}
onError={(error) => {
console.log(error);
}}
onPressLink={(uri) => {
console.log(`Link pressed: ${uri}`);
}}
style={styles.pdf}/>
Related
Does anyone know of a good library to use to collect a signature in Expo in both iOS and Android?
I've googled the heck out of it and tried half a dozen libraries but none seem to work well with Expo.
The closest one I've come across is https://github.com/brentvatne/signature-example but that works well on its own, but then has a bunch of issues when I bring it into my project.
I use react-native-signature-pad and it works great for me. Here's the link :
https://github.com/kevinstumpf/react-native-signature-pad
Example :
import SignaturePad from "react-native-signature-pad";
_signaturePadError = (error) => {
console.log("Error", error);
};
_signaturePadChange = ({ base64DataUrl }) => {
this.setState({ signature: base64DataUrl });
};
<SignaturePad
onError={this._signaturePadError}
onChange={this._signaturePadChange}
dotSize={2}
style={{
flex: 1,
backgroundColor: "white",
}}
/>```
I am new to Ionic development. I have been using Ionic2 for my application and trying to add push notification (FCM) for the last couple of hours. However, I am stuck in adding push configuration. Here are the details:
"phonegap-plugin-push": "^2.0.0" is configured in my package.json file. Also native push plugin is "#ionic-native/push": "^4.3.1"
In config.xml, I have added <resource-file src="google-services.json" target="google-services.json" />. Also added <plugin name="phonegap-plugin-push" spec="^2.0.0" />.
3.Here is the code I am using in my main component file:
const options: PushOptions = {
android: {
topics: ['topic1']
},
ios: {
alert: 'true',
badge: true,
sound: 'false'
},
windows: {},
browser: {
pushServiceURL: 'http://push.api.phonegap.com/v1/push'
}
};
const pushObject: PushObject = this.push.init(options);
pushObject.on('notification').subscribe((notification: any) => {
if (notification.additionalData.foreground) {
let pushAlert = this.alertCtrl.create({
title: 'BrainCal Notification',
message: notification.message.title
});
pushAlert.present();
}
});
pushObject.on('registration').subscribe((registration: any) => {
//do whatever you want with the registration ID
});
pushObject.on('error').subscribe(error => alert('Error with Push plugin' + error));
It is deployed successfully in my Android phone. However, it return following error while opening the app first time:
"Error with Push plugin no senderID value given".
As per my understanding latest phone gap plugin does not require senderID as it uses Google-services.json file. Please advise.
remove your plugin ionic cordova plugin remove phonegap-plugin-push then install it with parameters like below
ionic cordova plugin add phonegap-plugin-push --variable SENDER_ID=HERE_YOUR_SENDER_ID
I am developing an Ionic2 app. I am using Ionic STORAGE, which uses SQLITE in android. I want to preview that db for debugging. How can I do that. DDMS in android studio shows nothing.
I heard that Stetho is good for android app debugging. But couldn't found any tutorial how to integrate it with Ionic2.
Any help would be appreciated.
Rgds
You can :
console.log() database values and can see then in android studio debugger
Use a browser such as chrome in desktop and see database values(may not use sqllite)
more info
https://developers.google.com/web/tools/chrome-devtools/manage-data/local-storage
Use WebSQL for debugging:
import { Injectable } from '';
import { SQLite } from 'ionic-native';
import { Platform } from 'ionic-angular';
const DB_NAME: string = 'particulars.db';
const win: any = window;
#Injectable()
export class StorageService {
private _db: any;
constructor(private platform: Platform) {
if (this.platform.is('cordova')) {
this._db = new SQLite();
this._db.openDatabase({
name: DB_NAME,
location: 'default' // the location field is required
}).then(() => {
this._tryInit();
});
} else {
console.warn('Storage: SQLite plugin not installed, falling back to WebSQL. Make sure to install cordova-sqlite-storage in production!');
this._db = win.openDatabase(DB_NAME, '1.0', 'database', 5 * 1024 * 1024);
this._tryInit();
}
_tryInit() {
//do query here
}
}
See https://gist.github.com/NickStemerdink/64c782807fc31b7bc9b529ad4b1d56d5.
I've been trying hard to figure out how to check for network connectivity while the splashscreen is being displayed.I've searched for the code in many places but most of those articles are outdated.
I followed the tutorial that's mentioned here:https://www.thepolyglotdeveloper.com/2016/01/determine-network-availability-in-an-ionic-2-mobile-app/
But then I found out that Network.connection is deprecated and has been replaced by Network.type on the ionic2 website.
So I've replaced the word connection with Network.type everywhere.
So I checked out the ionic2 website and found this code which I included in the home.ts file.
import {Network} from 'ionic-native';
checkConnection() {
//console.log("entrou");
//console.log(Network);
let disconnectSubscription = Network.onDisconnect().subscribe(() => {
console.log('network was disconnected :-( ')
});
disconnectSubscription.unsubscribe();
console.log("watch network");
console.log("Conexao" + Network.type);
let connectSubscription = Network.onConnect().subscribe(() => {
console.log('network connected!');
setTimeout(() => {
console.log('network status');
console.log(Network.type);
if (Network.type === 'WIFI') {
console.log('we got a wifi connection, woohoo!');
}
}, 3000);
});
console.log("Sub" + connectSubscription);
connectSubscription.unsubscribe();
}
here is my home.html file
`<ion-header>
<ion-navbar>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<button ion-buttton (click)="checkConnection()">Check Network</button>
</ion-content>`
I tried implementing the same code but doesn't work.
I want to know what is the exact code that I can use ?
What is that I need to import to use this code if it is the right one?
Also I want to know how to run it during the splashscreen ?
On the console I found these errors
"Native: tried calling Network.type, but the Network plugin is not installed.
Network plugin: 'ionic plugin add cordova-plugin-network-information'
But i've already installed the required plugin following that above command.I also installed "npm install ionic-native".
I reinstalled them on seeing this error but this still persists.
In your config.xml add the following:
<preference name="AutoHideSplashScreen" value="false" />
This will make the SplashScreen stay visible until you manually hide it.
Then in your app.component.ts do the following:
constructor(private platform: Platform) {
platform.ready().then(() => {
// Check the network stuff here and do what you need to do
if (Network.type == 'WIFI') console.log('We are on WIFI!');
else console.log('We aren't on WIFI');
// then hide the splash screen manually
SplashScreen.hide();
});
}
hi, make sure you have ionic-native to the latest version:
https://github.com/driftyco/ionic-native/blob/master/CHANGELOG.md
please see this for implementation:
https://forum.ionicframework.com/t/using-ionic-2-rc-4-native-network/75715/4
there is another problem associated with this , where on disconnect fires twice rather than only once:
IONIC 2 native Network.onDisconnect() running code twice
I hope this helps.... besides there is no need to check during splashscreen.... make a provider for check network status, and then call your new provider/service in app.component.ts
Oh and dont pay attention to the message:Native: tried calling Network.type, but the Network plugin is not installed.
Just make sure you have added it correctly: ionic plugin add cordova-plugin-network-information --save
reference from this -
https://ionicframework.com/docs/native/network/
install :
$ ionic cordova plugin add cordova-plugin-network-information
$ npm install --save #ionic-native/network
and put this code in app.component.ts
import { Network } from '#ionic-native/network';
constructor(private network: Network) { }
// watch network for a disconnect
let disconnectSubscription =
this.network.onDisconnect().subscribe(() => {
console.log('network was disconnected :-(');
});
// stop disconnect watch
disconnectSubscription.unsubscribe();
// watch network for a connection
let connectSubscription = this.network.onConnect().subscribe(() =>
{
console.log('network connected!');
// We just got a connection but we need to wait briefly
// before we determine the connection type. Might need to wait.
// prior to doing any api requests as well.
setTimeout(() => {
if (this.network.type === 'wifi') {
console.log('we got a wifi connection, woohoo!');
}
}, 3000);
});
// stop connect watch
connectSubscription.unsubscribe();
and add code in to app.module.ts
import { Network } from '#ionic-native/network';
...
#NgModule({
...
providers: [
...
Network
...
]
...
})
export class AppModule { }`
Hope this will helpful.
I am trying deeplinks with ionic 2 according to the procedure explained here, https://ionicframework.com/docs/v2/native/ionic-deeplinks/
First I added the plugin using,
ionic plugin add ionic-plugin-deeplinks --variable URL_SCHEME=http --variable DEEPLINK_HOST=cityknots.com
Then in my app.component.ts
export class MyApp {
rootPage = Wrapper;
constructor(platform:Platform) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
StatusBar.styleDefault();
Deeplinks.route({
'/test': UserHome
}).subscribe((match) => {
console.log('Successfully routed', match);
}, (nomatch) => {
console.warn('Unmatched Route', nomatch);
});
});
}
}
I try to hit the url (http://cityknots.com/test in the ios simulator's browser (safari) after i've built and run the app, but nothing is happening. I expect the app should be launched and navigate to UserHome component. There is nothing in the console too related to this.