Determing iPad and iPhone models with pop up message - javascript

Please forgive my lack of knowledge!
I'm interested in creating a script/web application for my company and I've been diligently looking for the answer to my question.
Is it possible to detect iPhone or iPad models with useragent strings and then display a message to the effect of "You have an iPhone 5C"?...
If not, what are my other possible options?
I have seen quite a few posts about detecting if it were an iPad or and iPhone for browser formats.. and Also there is a SDK code that emulates the concept I'm trying to achieve.
I'm low on experience... but keen to learn!

The user-friendly name of the models are not available via API. Apps that I have been involved with that care use data compiled from several websites and build-up some kind of in-app list. You need both a list of models and their user-friendly name equivalents. Both are available via google searches. I don't know of a single, perfectly comprehensive, list, but a bit of searching will find several sites, whose data can be distilled into a single list.
To get the model number of the device to use as a key, the following code is used:
[UIDevice currentDevice].model

I assume you are trying to get the info from a visit to your website. You cannot know exact model of the device with web scripts, at least in my knowledge. But you can determine if the user is using an iPhone, iPad or iPod. Following are two options:
Javascript:
var Apple = {};
Apple.UA = navigator.userAgent;
Apple.Device = false;
Apple.Types = ["iPhone", "iPod", "iPad"];
for (var d = 0; d < Apple.Types.length; d++) {
var t = Apple.Types[d];
Apple[t] = !!Apple.UA.match(new RegExp(t, "i"));
Apple.Device = Apple.Device || Apple[t];
}
// is this an Apple device?
alert(
"Apple device? " + Apple.Device +
"niPhone? " + Apple.iPhone +
"niPod? " + Apple.iPod +
"niPad? " + Apple.iPad
);
PHP script:
// Apple detection array
$Apple = array();
$Apple['UA'] = $_SERVER['HTTP_USER_AGENT'];
$Apple['Device'] = false;
$Apple['Types'] = array('iPhone', 'iPod', 'iPad');
foreach ($Apple['Types'] as $d => $t) {
$Apple[$t] = (strpos($Apple['UA'], $t) !== false);
$Apple['Device'] |= $Apple[$t];
}
// is this an Apple device?
echo
"<p>Apple device? ", ($Apple['Device'] ? 'true' : 'false'),
"</p>n<p>iPhone? ", ($Apple['iPhone'] ? 'true' : 'false'),
"</p>n<p>iPod? ", ($Apple['iPod'] ? 'true' : 'false'),
"</p>n<p>iPad? ", ($Apple['iPad'] ? 'true' : 'false'),
'</p>';
For more information, read here.
Since your tags and statement is a bit confusing, just on the off-chance that If you are using iOS sdk and building an iOS app, you can simply get the model from one line like:
[[UIDevice currentDevice] platformString]

Related

Pushwoosh Cordova API: Can two different devices ever generate the same HWID?

Our app uses HWIDs generated by Pushwoosh as a key to differentiate devices. Looking over traffic logs, I am seeing what looks like the same device submitting HTTP requests from several different ISPs over short timeframes.
It appears that different devices from all over the internet are generating the same HWID, which our app is treating as the same device causing issues with users interfering with each other. Our data is showing about 50 requests appear to be from different devices, but using the same HWID.
This makes no sense to me -- from what I've read about HWIDs, they are based on the device serial number, so they should always be unique.
Our mobile app is written in Cordova, and we are getting HWIDs with this code:
get_hwid: (evt) =>
_this = #
regid = device.uuid
if evt? && evt.detail?
push_notification_id = evt.detail.deviceToken
else
push_notification_id = ""
pushNotification = cordova.require("pushwoosh-cordova- plugin.PushNotification")
pushNotification.getPushwooshHWID (hwid) ->
_this.debug 'in getPushwooshHWID callback'
_this.debug ' Pushwoosh HWID: ', hwid
_this.debug ' push_notification_id: ', push_notification_id
_this.debug ' regid: ', regid
_this.emit 'retrieved-hwid',
regid: regid
push_notification_id: push_notification_id
hwid: hwid
Has anyone observed the PushWoosh API generate HWIDs that weren't always unique?
The PushWoosh docs say that sometimes HWIDs can change on the same device, but I can't find anything that suggests that they can't be expected to be unique.
Thanks!
HWID's (which are IDFV/IDFA) are unique. The only way they may change (to another unique value) is when user restores a backup on a device.
If you see the same HWID's make sure your Pushwoosh SDK are >= 4.1.2
as outlined here
https://www.pushwoosh.com/blog/pushwoosh-sdk-update-ios-10-makes-difference/

chrome.management.getAll does not return Chrome Store's app data

I am now writing a new tab page replacement for Chrome 33.
While I am using chrome.management.getAll() to get app list, I found a strange thing.
Here is my code:
document.addEventListener('DOMContentLoaded', function () {
...
chrome.management.getAll(getAllApps);
...});
function getAllApps(data) {
...
console.log("Installed App Count:" + data.length);
for (var i = data.length - 1; i >= 0; i--) {
console.log("Found App: " + data[i].name + " type:" + data[i].type);
if (data[i].type == 'theme' ||
data[i].type == 'extension' ) {
continue;
};
...
}
}
The output never lists Chrome Store.
But if I use chrome.management.get(), I could get the record of Chrome Store by its id.
Is there anything wrong in my code? Or is the Store is intended to be hidden?
Thank you. It is my first question here, so if there is any inappropriate words in my question, please forgive me.
The Store app is a component extension. Those extensions are built in to Chrome, not installed. As you can see from the documentation, getAll() returns only the user's installed extensions.
Your best bet is to hardcode the list of extensions that appear in a brand-new profile, which will consist only of component items (unless you're on a machine you don't control). Over time that list will diverge from the canonical list in the source code.
Both chrome.management.get() and chrome.management.getAll() show information about apps/extensions/themes installed on local computer, not information from Chrome Web Store.

Getting MAC Address in Mozilla, ActiveXObject is not working

var locator = new ActiveXObject("WbemScripting.SWbemLocator");
var service = locator.ConnectServer(".");
var properties = service.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration");
var e = new Enumerator(properties);
var MACaddress = '';
alert("Its Inside");
for (; !e.atEnd(); e.moveNext()) {
var p = e.item();
if (p.MACAddress) {
MACaddress = MACaddress + p.MACAddress + ',';
}
}
MACaddress = MACaddress.substring(0, MACaddress.length - 1);
MACaddress = replaceAll(MACaddress, ':', '-');
location.href = location.href + '?CAT=MAC&MACAddr=' + MACaddress;
This function is working fine in IE but its breaking in mozilla firefox at the first line itself. I changed locator.ConnectServer(".") to locator.ConnectServer("MACHINE") but still its not working in Mozilla Firefox.
Simple answer: you can't.
Modern browsers sandboxes (or try to) everything that goes on in the browser for security reason. Sand-boxing prevents any direct access to a system incl. files system, hardware etc. (it doesn't mean the browser does not communicate with the hardware but as users we have not direct access to it).
IE is the only browser which supports ActiveX (which is Microsoft's own technology) but it shouldn't be relied upon for the same reason, (mainly..) security.
If you want to use the MAC-address for some sort of unique identifier/security you can instead look into the new Web Cryptography API, however, at the time of this writing it is still in draft mode and not widely supported (but will be, or intents to be, cross-browser sometime in the future) so perhaps not so very useful advice at the moment.
You can in any case use server side to generate a unique identifier based on various factors and store it locally in the browser using either cookies or localStorage and so forth.

Platform-Independent JS->Native Bridge?

I'm currently working on an app that aggressively uses webviews on both iOS and Android to render content, with native chrome surrounding it. I want to be able to control this chrome via javascript methods.
Android Webview has addJavascriptInterface which allows this to happen, but iOS does not have this facility. I've already checked out the SO answer at iOS JavaScript bridge, and this has usefuleinformation, but It's iOS-only; optimally the same underlying web code could power the callbacks on both Andorid and iOS devices.
I'm wondering if something like PhoneGap or Appcelerator provides a way to do this simply; however I don't need their core product (providing a native experience via underlying html/css/js) and I dont even know if what I need is included in their package.
Thanks for any info!
I would say that the best way would be to do it yourself, combining those two examples:
function nativeDoStuff() {
if (androidbridge != null {
androidbridge.doStuff();
}
else {
//construct url
window.location = "myiphonescheme://dostuff";
}
come to think of it, if you're feeling ambitious you could code up a quick javascript object to do it for you:
function NativeAppBridge () {
function runMethod(methodName, params) {
if (androidbridge != null {
// If the android bridge and the method you're trying to call exists,
// we'll just call the method directly:
if (androidbridge[methodName] != null) {
androidbridge[methodName].apply(this, params);
}
}
else {
// building the url is more complicated; best I can think
// of is something like this:
var url = "myiphonescheme://" + methodName;
if (params.length > 0) {
url += "?"
var i = 0;
for (param in params) {
url += "param" + i + "=" + param;
++i;
if (i < params.length) {
url += "&";
}
}
}
}
}
}
Using it would then be as simple as:
var bridge = new NativeAppBridge();
function onClick() {
bridge.runMethod("doStuff", null);
}
Be aware that I coded this off the top of my head and don't have time to test, at the moment - but I think it should work well enough, provided I didn't make any major mistakes
You can try the XWebView project if you plan to use WKWebView
You can use phonegap plugins to do it. They provide an excelent way to communicate between their webview and your native layer.
Here you can see how to create one!
And my personal opinion on the subject: I've been using phonegap for a while and if you are on webviews, I strongly suggest you to rethink the way you're doing stuff and move to a mobile web platform. You probably can save a lot of time.
The way I see it, the great disadvantage on using this is you are creating a webpage instead of a mobile app. You cant use native components and your app gets less responsive. As you are already on webviews, I believe you can only find benefits on these platforms.

openDatabase creates error in Android PhoneGap application

I built a basic phone app using HTML5 and JavaScript (including JQTouch), and then used PhoneGap to turn it into an Android app (after many traumas - seems that PhoneGap and Windows computers don't get along too well).
The app works well in Chrome, but on an Android emulator the following error shows up in LogCat:
06-07 21:38:51.711: DEBUG/WebCore(204): Console: ReferenceError: Can't find variable: openDatabase line: 9 source: file:///android_asset/www/handicap.js
This refers to the following line in handicap.js:
db = openDatabase('Handicaps', '1.0', 'Handicaps', 65536);
The wider context of this piece of code is:
// initialise all important functions
$(document).ready(function(){
$('#newrace form').submit(saveRace);
$('#newrace form').submit(setTitle);
$('#enterhandicaps form').submit(savePrediction);
$('#enterhandicaps form').submit(refreshEntries);
$('#calcraces').click(raceList);
// create database to hold data on predicted and actual times
db = openDatabase('Handicaps', '1.0', 'Handicaps', 65536);
db.transaction(
function(transaction) {
transaction.executeSql(
'CREATE TABLE IF NOT EXISTS predictions (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,racename TEXT NOT NULL, runner TEXT NOT NULL, prediction INTEGER, start TEXT, finish TEXT, position TEXT);'
);
transaction.executeSql(
'CREATE TABLE IF NOT EXISTS races (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,racename TEXT NOT NULL, date TEXT, distance REAL);'
);
transaction.executeSql(
'CREATE TABLE IF NOT EXISTS autocompletion (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,runner TEXT NOT NULL, value TEXT,racename TEXT NOT NULL);'
);
}
);
}
);
On looking at other people having similar problems on stackoverflow, I've tried the suggestion of using only Android versions below 2.2 but that has not helped. Any other suggestions?
Could be something very obvious that I've missed, as I'm completely new to this.
The complete code for the app in web browser form is at https://github.com/fhr/Handicap-timer-app if that helps.
Can you share your app code in the app format with all the references to phonegap.js and so on ? Also I do not see your code using the window object. As per the phonegap apis the correct way to use the openDatabase() is var db = window.openDatabase(). Also, it would help if you could also mention the version of pg that you are using.
well i think its trying to open the file "file:///android_asset/www/handicap.js"
as opposed to where a db normally is //data/data//database/dbfile (normally no extension)
please post more code
i think its the opendatabase that your using.
Override onExceededDatabaseQuota method in your WebChromeClient Object.
#Override
public void onExceededDatabaseQuota(String url, String databaseIdentifier,
long currentQuota, long estimatedSize, long totalUsedQuota,
WebStorage.QuotaUpdater quotaUpdater) {
Log.d("test", "onExceededDatabaseQuota : " + " currentQuota=" + currentQuota
+ " estimatedSize=" + estimatedSize + " totalUsedQuota=" + totalUsedQuota);
quotaUpdater.updateQuota(estimatedSize * 2);
}

Categories

Resources