How to check for iOS5 using web technologies? - ios

I'm working on a mobile app using jQuery Mobile and I would like to check if I'm on iOS5, cause it has some great features, like true fixed toolbars, etc. I'm looking for a javascript solution.

This works for me with a bit of string manipulation of the user-agent.
var ua = navigator.userAgent;
var detail = ua.split('(')[1];
var device = detail.split(';')[0];
if (device == 'iPhone' || device == 'iPod' || device == 'iPad') {
var ios = detail.split(' ')[5].split('_')[0];
if (ios == '5') {
alert('ios 5');
}
}

Related

android 12 AudioManager.setCommunicationDevice not working

I'm building a voice call app for android using WebView. Everything works fine except in android 12, I can not use the earpiece (or even wired headphones in some phones) for audio out. The audio is always playing through loudspeaker. And some of the users reported that they can hear the internal ring(Which is a MediaPlayer object) in earpiece, but once the call answered it switches to loudspeaker. And the worst part is, I'm not able to reproduce this issue as this works perfectly on all my test phones (android 12).
My code,
private fun setAudioOutDevice(target: AudioDeviceInfo?) {
//need some delay for bluetooth sco
var audioChangeDelay: Long = 15
if (System.currentTimeMillis() - lastAudioChangeTime <= 300) audioChangeDelay = 300
Handler(Looper.getMainLooper()).postDelayed({
var targetDevice = target
//no device selected. scan all output devices and select one automatically
if (targetDevice == null) {
var wiredHeadsetDevice: AudioDeviceInfo? =
getAudioDevice(AudioDeviceInfo.TYPE_WIRED_HEADSET)
if (wiredHeadsetDevice == null) wiredHeadsetDevice =
getAudioDevice(AudioDeviceInfo.TYPE_WIRED_HEADPHONES)
val bluetoothDevice: AudioDeviceInfo? =
getAudioDevice(AudioDeviceInfo.TYPE_BLUETOOTH_SCO)
val speakerDevice: AudioDeviceInfo? =
getAudioDevice(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER)
val earpieceDevice: AudioDeviceInfo? =
getAudioDevice(AudioDeviceInfo.TYPE_BUILTIN_EARPIECE)
//update global variables
isBluetoothAvailable = bluetoothDevice != null
//disable BT if wired headset connected
if (wiredHeadsetDevice != null) isBluetoothAvailable = false
//choose an output device
targetDevice =
if (callType == videoCall && bluetoothDevice == null && wiredHeadsetDevice == null) speakerDevice
else if (callType == videoCall && wiredHeadsetDevice == null && !isBluetoothAudioEnabled) speakerDevice
else wiredHeadsetDevice
?: if (isBluetoothAvailable && isBluetoothAudioEnabled && bluetoothDevice != null) bluetoothDevice
else earpieceDevice ?: speakerDevice
//no earpiece
if (earpieceDevice == null) {
setBigStatus("Unable to access Earpiece", 0)
}
}
//set output device
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
var success = false
try {
// am.clearCommunicationDevice()
if (targetDevice != null) success = am.setCommunicationDevice(targetDevice)
} catch (e: Exception) {
debugMsg(e.message.toString())
}
if (!success) setBigStatus(getString(R.string.unable_to_set_audio), 0)
}
//older devices, android 11 or lower
else {
am.mode = AudioManager.MODE_IN_COMMUNICATION
if (targetDevice?.type == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
changeSco(false)
am.isSpeakerphoneOn = true
} else {
if (targetDevice?.type == AudioDeviceInfo.TYPE_BLUETOOTH_SCO) changeSco(true)
else changeSco(false)
am.isSpeakerphoneOn = false
}
}
}, audioChangeDelay)
}
private fun changeSco(enable: Boolean) {
if (enable) {
am.startBluetoothSco()
am.isBluetoothScoOn = true
} else {
am.stopBluetoothSco()
am.isBluetoothScoOn = false
}
}
private fun getAudioDevice(type: Int): AudioDeviceInfo? {
val audioDevices = am.getDevices(AudioManager.GET_DEVICES_OUTPUTS)
for (deviceInfo in audioDevices) {
if (type == deviceInfo.type) return deviceInfo
}
return null
}
The above code is working fine on android 11 and lower and even on some android 12 phones. How can I make this work on all devices?
There is an issue tracker here. But it seems that nobody is working on it.
UPDATE Today I tried it on a pixel 3a and it gives mixed behaviors. Sometimes it plays on the earpiece or wired headset but for most of the calls, it plays on the loudspeaker only. And even if I don't set any mode, it automatically switches to MODE_IN_COMMUNICATION right after the stream starts. I think, android is trying to figure out the proper mode by itself and that messing with my app logic.

Xamarin ios ZXING scanner not analyzing QR

i'm using an Iphone 10 with ios 15.3.1,Zxing version = 2.4.1, compiling the xamarin project in windows. I been trying to make a qr scanner with zxing for ios android, but when i run my app in ios, it won't go to the onResult event. I've tried with a lot of methods of doing this, but nothing seems to work. The camera shows, but the result never comes truh. ¿Does someone have any idea why this is happening? I also tried apps from other devs that are using zxing and it also dosen't work. but when i scan with the camera app it works.
async void OnButtonClickedAsync(object sender, System.EventArgs e)
{
var options = new ZXing.Mobile.MobileBarcodeScanningOptions
{
CameraResolutionSelector = HandleCameraResolutionSelectorDelegate
};
MobileBarcodeScanner scanner = new MobileBarcodeScanner();
//scanner.TopText = "Hold camera up to barcode to scan";
//scanner.BottomText = "Barcode will automatically scan";
//scanner.UseCustomOverlay = false;
scanner.FlashButtonText = "Flash";
scanner.CancelButtonText = "Cancel";
scanner.Torch(true);
scanner.AutoFocus();
var result = await scanner.Scan(options);
HandleScanResult(result);
}
void HandleScanResult(ZXing.Result result)
{
if (result != null && !string.IsNullOrEmpty(result.Text))
scanResultText.Text = result.Text;
}
CameraResolution HandleCameraResolutionSelectorDelegate(List<CameraResolution> availableResolutions)
{
//Don't know if this will ever be null or empty
if (availableResolutions == null || availableResolutions.Count < 1)
return new CameraResolution() { Width = 800, Height = 600 };
//Debugging revealed that the last element in the list
//expresses the highest resolution. This could probably be more thorough.
return availableResolutions[availableResolutions.Count - 1];
}
I compiled using a mac and it worked fine, must be a bug of visual studio on windows.

How to check the “Allow Full Access” is enabled in iOS 11?

How to check the “Allow Full Access” is enabled in iOS 11?
I have tried multiple methods which do not seem to be working in iOS 10 or iOS 11.
Here is one that I tried:
func hasFullAccess() -> Bool
{
var hasFullAccess = false
if #available(iOSApplicationExtension 10.0, *) {
let pasty = UIPasteboard.general
if pasty.hasURLs || pasty.hasColors || pasty.hasStrings || pasty.hasImages {
hasFullAccess = true
} else {
pasty.string = "TEST"
if pasty.hasStrings {
hasFullAccess = true
pasty.string = ""
}
}
} else {
// Fallback on earlier versions
var clippy : UIPasteboard?
clippy = UIPasteboard.general
if clippy != nil {
hasFullAccess = true
}
}
return hasFullAccess
}
Every time it returns true and I am running this on a device not on the simulator.
First of all, it feels like you're checking the iOS version wrong. It usually looks like this if #available(iOS 11.0, *) where iOS version you pass is the latest one you use. In your declaration iOS 11 is not even there, it checks for iOS 10 and below.
Second, you're using || which is OR operator. So if any of those statements is true, the whole thing will return true. You need && the AND operator to check whether everything is matching.

Need WURFL to work only for mobiles

At present i am using the below code for detecting mobiles, tablets. But i need to restrict this code to Mobile. Your suggestions can be appreciated if provided the solution.
DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("Mobile")
{
ContextCondition = (context =>
{
var manager = (context.Cache[WurflManagerCacheKey] as IWURFLManager);
var cabablities = manager.GetDeviceForRequest(context.Request.UserAgent);
return cabablities.GetCapability("is_wireless_device") == "true";
//return cabablities.GetCapability("mobile_browser").Contains("Opera");
//return cabablities.UserAgent.Contains("Opera");
})
});
I would use the is_wireless_device and is_tablet capabilities to isolate only mobile phones:
if (is_tablet == false && is_wireless_device == true) {
//Must be a mobile phone
}

dart2js compiled code running in an unsupported browser

What happens if I try to run my generated javascript code in an unsupported browser? Like IE6?
I don't want to end up in a situation that my users will see a partly working broken app. Is there a way how to ensure that the dart/javascript will run only if the browser is supported and have my app degrade gracefully to some html banner "use a newer browser please" if it is not?
You could use the browser detector script here: http://www.quirksmode.org/js/detect.html
I wrote this code from the top of my head, I don't have a testing machine at my disposal right now:
var isNewFirefox = BrowserDetect.browser === 'Firefox' && BrowserDetect.version >= 7;
var isNewChrome = BrowserDetect.browser === 'Chrome';
var isNewIE = BrowserDetect.browser === 'Explorer' && BrowserDetect.version >= 9;
var isNewSafari = BrowserDetect.browser === 'Safari' && BrowserDetect.version >= 5.1;
var isNewOpera = BrowserDetect.browser === 'Opera' && BrowserDetect.version >= 12;
if (isNewFirefox || isNewChrome || isNewIE || isNewSafari || isNewOpera) {
var script = document.createElement('script');
if (navigator.webkitStartDart || navigator.startDart || navigator.mozStartDart || navigator.oStartDart || navigator.msStartDart) {
// Load Dart code!
script.setAttribute('type', 'application/dart');
script.setAttribute('src', 'http://.../foo.dart');
} else {
// Load dart2js code!
script.setAttribute('src', 'http://.../foo.js');
}
document.body.appendChild(script);
} else {
alert('Application wont work');
}
The version information can be found on: http://www.dartlang.org/support/faq.html#what-browsers-supported
Dart VM detection: http://www.dartlang.org/dartium/#detect
You can always detect browser in pure javascript and do not run dart program till you make sure browser is valid.

Resources