Detect if sensors are available on a Windows 8 device - gps

How to detect if a sensor is available on a Windows 8 device? My app needs GPS to work properly, so I need a way to detect if it is available on the device it is running on.

Here are some available sensors for Windows 8 devices.
you can check if they are available by GetDefault() method. It returns 'null' if the sensor is not available.
if(Accelerometer.GetDefault() != null)
{
// your code
}
if (Compass.GetDefault() != null)
{
// your code
}
if (Gyrometer.GetDefault() != null)
{
// your code
}

you can check the LocationStatus property of the Geolocator object... if it is NotAvailable or Disabled you are out of luck...

Related

bluetooth background mode IOS when the screen is locked

I would like to implement background bluetooth scanning on IOS. When the application goes in background mode it calls TestCentralManagerDelegate which implements DiscoveredPeripheral function. It is triggered when a new bluetooth peripheral device is detected. If a new bluetooth device is detected the application read the manufacture data which is presented in Dictionary advertisementData (as argument of DiscoveredPeripheral function). The manufacture data are obtained by calling ManufactureData = advertisementData["kCBAdvDataManufacturerData"].ToString(). The discovering of the manufacture data was tested on two different iPhones 5s and 6 with the same iOS 12.1. When the application goes in background mode, I locked the screen.
In the case of iPhone 5s, I observed that ManufactureData was found each time
the DiscoveredPeripheral function is triggered. This fact is not true for iPhone 6, each time I got ManufactureData = null. It is worth mentioning that the manufacture data are received in both cases if the screen is not locked.
I do not understand why the iPhone 6 does not find ManufactureData, meanwhile the iPhone 5s does. I would accept the fact that phones have different operating systems and this implies different responses, but in my case this is not the case. I will appreciate any help for better understanding aforementioned problem.
Here is code I am using Xamarin.iOS.
public override void DiscoveredPeripheral(CBCentralManager central, CBPeripheral peripheral, NSDictionary advertisementData, NSNumber RSSI)
{
try
{
central.StopScan();
if (peripheral == null || advertisementData == null)
{
central.ScanForPeripherals(cbuuids);
return;
}
string ManufactureData;
if (advertisementData.ContainsKey(new NSString("kCBAdvDataManufacturerData")))
{
ManufactureData = advertisementData["kCBAdvDataManufacturerData"].ToString();
}
else
{
ManufactureData = null;
CrossLocalNotifications.Current.Show("no advertising data", "no advertising data", 10);
central.ScanForPeripherals(cbuuids);
return;
}
central.ScanForPeripherals(cbuuids);
}
catch
{
central.ScanForPeripherals(cbuuids);
}
}

CoreMediaIO, an alleged OS Bug / Memory Leak

Environment
OS-X 10.10
xcode 6.4
C++/Obj-C OS-X application
Use-case
Capture video using CoreMediaIO, capture source is iPod5
Capturing machine is OS-X Yosemite
Capture feed consists of Video and Audio samples
Problem description
While video capture is working fine, when video samples are received, there is an accumulating memory leak, when no video samples are received ( only audio ), there is no leak ( memory consumption stops growing )
I am mixing Cocoa thread and POSIX threads, I have made sure to have [NSThread isMultiThreaded] set to YES ( by creating an empty NSThread )
"Obj-C Auto Ref Counting" is set to YES in the project properties
The following is a short code-snap of the code causing the leak:
OSStatus status = 0;
#autoreleasepool {
m_udid = udid;
if (0 != (status = Utils::CoreMediaIO::FindDeviceByUDID(m_udid, m_devId)))
return HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
if (0 != (status = Utils::CoreMediaIO::GetStreamByIndex(m_devId, kCMIODevicePropertyScopeInput, 0, m_strmID)))
return HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
status = Utils::CoreMediaIO::SetPtopertyData(m_devId, kCMIODevicePropertyExcludeNonDALAccess, 1U);
status = Utils::CoreMediaIO::SetPtopertyData<int>(m_devId, kCMIODevicePropertyDeviceMaster, getpid());// Exclusive access for the calling process
// Results in an infinitely accumulating memory leak
status = CMIOStreamCopyBufferQueue(m_strmID, [](CMIOStreamID streamID, void* token, void* refCon) {
#autoreleasepool {
CMSampleBufferRef sampleBuffer;
while(0 != (sampleBuffer = (CMSampleBufferRef)CMSimpleQueueDequeue(m_queueRef))) {
CFRelease(sampleBuffer);
sampleBuffer = 0;
}
}
}, this, &m_queueRef);
if(noErr != status)
return E_FAIL;
if(noErr != (status = CMIODeviceStartStream(m_devId, m_strmID)))
return E_FAIL;
}
Having sample de-queuing done in the main thread ( using 'dispatch_async(dispatch_get_main_queue(), ^{' ) didn't have any affect...
Is there anything wrong with the above code snap? might this be an OS Bug?
Reference link: https://forums.developer.apple.com/message/46752#46752
AN UPDATE
The QuickTime player support using an iOS device as a capture source ( mirroring it's A/V to the mac machine ), having a preview session running for a while reproduce the above mentioned problem w/ the OS provided QuickTime player, this strongly indicate an OS Bug, bellow is a screen-shot showing the QT player taking 140Mb of RAM after running for ~2hours ( where it starts around 20Mb ), by the end of the day it has grown to ~760Mb...
APPLE Please have this Fixed, I have standing customers commitments...

Record audio from non-default audio device in objective C

We know there is no API for recording live streaming audio of OS X ( output sound). And we should install a kernel extension like SoundFlower and then record audio of output channel through that kernel extension.
I'm aware that some open source apps like audacity use Port Audio library to capture audio of another audio devices other than default audio device of system. But I couldn't compile Port Audio because of too much errors when building it on Xcode.
I want to know there is a straight forward Core Audio API which has capability of choosing record device? AudioQueue API has no ability to determine type of record device.
How to record output sound which is being played through SoundFLower in objective C with use of some specific Mac provided API?
Thanks in advance for your responses.
This is the relevant code used in SoundFlowerBed to find and select specific audio devices:
/* From Interface */
AudioDeviceID mSoundflower2Device;
AudioDeviceID mSoundflower16Device;
/* Implementation */
// find soundflower devices, store and remove them from our output list
AudioDeviceList::DeviceList &thelist = mOutputDeviceList->GetList();
int index = 0;
for (AudioDeviceList::DeviceList::iterator i = thelist.begin(); i != thelist.end(); ++i, ++index) {
if (0 == strcmp("Soundflower (2ch)", (*i).mName)) {
mSoundflower2Device = (*i).mID;
AudioDeviceList::DeviceList::iterator toerase = i;
i--;
thelist.erase(toerase);
}
else if (0 == strcmp("Soundflower (16ch)", (*i).mName)) {
mSoundflower16Device = (*i).mID;
AudioDeviceList::DeviceList::iterator toerase = i;
i--;
thelist.erase(toerase);
}
else if (0 == strcmp("Soundflower (64ch)", (*i).mName)) {
mSoundflower16Device = (*i).mID;
AudioDeviceList::DeviceList::iterator toerase = i;
i--;
thelist.erase(toerase);
}
}
You'll need to download the source form here: https://github.com/mattingalls/Soundflower and include AudioDevice and AudioDeviceList files in your project.

How to detect if Windows 8 device is on WiFi/LAN or 3G Internet connection?

Is there a way how to detect if current Windows 8 device is using Internet from WiFi/LAN or from 3G connection? We have to provide different image and video quality in our app based on the network speed.
I've so far only checked the ConnectionCost and NetworkAdapter API, but I'm not sure, if this is what I want:
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh700381.aspx
You can find network type with NetworkAdapter class. It has property IanaInterfaceType. To check all the IANA interface, go here
var profile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
var interfaceType = profile.NetworkAdapter.IanaInterfaceType;
// 71 is WiFi & 6 is Ethernet(LAN)
if (interfaceType == 71 || interfaceType == 6)
{
//TODO:
}
// 243 & 244 is 3G/Mobile
else if (interfaceType == 243 || interfaceType == 244)
{
//TODO:
}
The NetworkInformation ,ConnectionCost and the other network APIs exist to help with your scenario. Is it missing some functionality that you need for your specific app?
Kraig Brockschmidt has a nice implementation of a network connectivity test on his blog that might be what you are looking for.

Objective-c iOS 5.x - Check if the iDevice is connected to a computer

I want to check if an iOS device is currently connected to a computer (Wifi And Cable)
I tried to google it and looked into the Apple Developer site, but couldn't seem to find anything related to my question.
If the device is physically connected you can check the battery state, like so:
UIDeviceBatteryState myBatteryState = [UIDevice currentDevice].myBatteryState;
if (myBatteryState == UIDeviceBatteryStateCharging) {
//code
} else if (myBatteryState == UIDeviceBatteryStateFull) {
//code
}