I have an meteor app that is deployed for both ios and android device and i want certain code to run on only ios device and not on android. I know that I can detect device using meteor device-detection package like
Meteor.Device.isPhone()
But is there any possible way can know if its an android or iOS device.
EDIT: I have created bundle using meteor cordova.
Here's a global helper that should do the trick as far as detecting iOS:
Template.registerHelper('isIOS',() => {
return ( navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false );
});
And another for Android:
Template.registerHelper('isAndroid',() => {
return navigator.userAgent.toLowerCase().indexOf("android") > -1;
});
To use anywhere in client js:
Blaze._globalHelpers.isIOS()
Blaze._globalHelpers.isAndroid()
And of course, to use in html template markup:
{{#if isIOS}}...{{/if}}
{{#if isAndroid}}...{{/if}}
Related
I'm developing a ChromeOS kiosk application (website + chrome extension) which suppose to run in Kiosk Mode on managed Chromebook devices. Application displays external web content which I don't own, I'm using sandboxed iframes to display that web content. These external websites should not escape their iframes, that's why I sandbox them. The app is basically a simple web browser but instead of tabs I use iframes, and the top frame (window.top) is the wrapper around these iframes.
With all ChromeOS technical limitations I was able to bypass most of the iframe checks (x-frame-options, csp, blocked 302...) using the extension. However there is one I'm stuck with - framekillers. I can't properly display websites which do self !== top type of checks.
Is there a way to bypass it too somehow? I'm fine with refactoring my app completely or use something else instead of iframe. The app has to fulfil only one condition though - kiosk mode on a managed chromebook.
It's unfortunate that Chrome Apps with <webview> tag were deprecated and Android apps can't run in Kiosk mode anymore. This would solve all my issues easily by just using something else than iframes.
I've tried injecting the following buster <script> via a content script but it doesn't seem to work, websites seems to be doing something more advanced.
buster.ts
function buster() {
if (top !== self) {
(window.self as any) = window.top;
(window.parent as any) = window.top;
}
}
buster();
content-script.ts
const b = document.createElement('script');
b.src = chrome.runtime.getURL('buster.js');
const el = document.head || document.documentElement;
el.insertBefore(b, el.firstChild);
console.debug('buster is injected');
solution based on #wOxxOm comment (for MV3 extension):
background.ts
chrome.scripting.registerContentScripts([
{
allFrames: true,
id: 'some-id',
js: ['buster.js'],
matches: ['<all_urls>'],
runAt: 'document_start',
world: 'MAIN',
},
]);
buster.ts
function buster() {
if (top !== self) {
(window.self as any) = window.top;
}
}
buster();
I have just an Android app and no iOS app. So I was trying to set a fallback url (to our web content) when any iOS user clicks on the dynamic link.
I am constructing a firebase dynamic link using the dynamic-links-ktx apis like this:
Firebase.dynamicLinks.shortLinkAsync(ShortDynamicLink.Suffix.SHORT) {
androidParameters(BuildConfig.APPLICATION_ID) {
fallbackUrl = Uri.parse(webUrl)
}
iosParameters(BuildConfig.APPLICATION_ID) {
setFallbackUrl(Uri.parse(webUrl)) // Show web content. <- This doesn't work
}
link = Uri.parse(finalUrl)
domainUriPrefix = "https://prefix-url"
socialMetaTagParameters {
...
}
}.addOnSuccessListener { result ->
onSuccess(result.shortLink)
}.addOnFailureListener {
// Log error
}
So, this way I create the deep link. I don't have an ios app so obviously I cannot set ios bundle name etc so I am setting just setFallbackUrl in iosParameters.
Somehow this doesn't work. On viewing the deeplink flowchart, ios doesnt resolve to the fallback url. Am i missing something here?
You need to have ibi (iOS ID) set for the ifl (iOS fallback link) to work.
I think this is an oversight by the Firebase team, it makes sense to either use ofl or let us set ifl instead of the deeplink when the app doesn't exist on iOS, but it is what it is.
Notifee Notification icon not working in the notifee display notification
notifee.displayNotification({
title: remoteMessage.notification.title,
body: remoteMessage.notification.body,
android: {
channelId: 'android_id',
},
});
I have used so many things like, small_icon,large_icon and other ways but notification icon is not diplaying it is just showing a default image.
I also checked with AndroidManifest meta data tags, they are also not working.
Small assets are size sensitive. So if we provide a custom image size, it may not work. It is better to generate and add using android studio 'add asset' wizard.
inside android node, we just need to add the small icon name, which is added using android studio.
android: {
smallIcon: 'ic_small_icon',
}
Where, the ic_small_icon, is added as a image asset through android studio.
Follow below link to add android asset through android studio.
How to check Mobile/Web in HTML Meteor for loading UI? .
if mobile //here how to check if it is mobile or web
{
{{>template}}// mobile body
}
else
{
{{>template}}//web body
}
I am new to Meteor. So please suggest me what to do?
You can do that easily with device-detection package.
First, install it via:
meteor add mystor:device-detection
Then you can use the provided helper methods like Meteor.Device.isPhone(), or directly from Spacebars: {{#if isPhone}}Phone{{/if}}. See the readme on Github for details.
If you simply want to check whether the app is running on a mobile environment you can use:
if(Meteor.isCordova)
Check out the other functions as well
If someone is still looking for this, he can try this JS test:
if (/Mobi/.test(navigator.userAgent)) {
//on Mobile
}else{
//not on mobile
}
I have a strange problem with my iPad App in Phone Gap. The problem is that I have to open PDF document in my app through links and when I click the link which opens the PDF, it shows me the PDF document with no back link.
Hence, when I open the PDF document in my app through a link, it takes me to a dead end and there is no way I can go back to the main page of my app.
My question is that how can I have a Top-Bar, when I open a PDF which could take me back to my home page? Any internal element for the iPad may be?
Thanks a lot.
Try using the In App Browser plugin.
If you're using a later Phonegap / Cordova version (2.8.0, 2.9.0 etc) it should come with it - nothing else to install.
http://docs.phonegap.com/en/2.9.0/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser
It will allow you to open the PDF in the a new 'window' that overlays your app. It has a 'Done' button that users can use to close it and return to your app when they are finished.
You would open the PDF using the In-App Browser, using something like this:
window.open('http://whitelisted-url.com/pdftoopen.pdf', '_blank');
I.e. the _blank option triggers the In-App Browser plugin. If you were to use _system instead it might open it in iBooks (just guessing there - not 100% sure if it would use iBooks).
Try prefixing https://docs.google.com/viewer?url= in the URL
like, window.open('https://docs.google.com/viewer?url=http://www.example.com/example.pdf&embedded=true', '_blank', 'location=yes');
Try this to open any kind of documents from URL using following steps:
install this plugin : cordova plugin add https://github.com/ti8m/DocumentHandler
use this code :
handleDocumentWithURL(function() { console.log('success'); }, function(error) { console.log('failure'); if (error == 53) { console.log('No app that handles this file type.'); } }, 'http://www.example.com/path/to/document.pdf');
It works for me both on Android and IOS. I used it for open images and PDF files.
Android : It opens files using system apps if available, otherwise it give an error, which you can handle.
IOS : It opens files in popup like view with Done button and Option button.
It doesn't show your docs URL.
Source is available here : https://github.com/ti8m/DocumentHandler
Thanks asgeo1,
I solved it by using window.open().
<img src="images/samplens.jpg" border="0" />
Hope it helps.
I've ended up using WebIntent
as described here. The tricky part was to modify WebIntent.java to properly identify file type:
String type = obj.has("type") ? obj.getString("type") : null;
// New code starts
Uri uri = obj.has("url") ? Uri.parse(obj.getString("url")) : null;
String extension = MimeTypeMap.getFileExtensionFromUrl(obj.getString("url"));
if(extension != null){
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
type = mimeTypeMap.getMimeTypeFromExtension(extension);
}
// New code ends
JSONObject extras = obj.has("extras") ? obj.getJSONObject("extras") : null;