Find device orientation using Accelerometer data x,z,y - iphone

How can we find the device orientation from x,y,z(accelerometer).
I was trying to get the device orientation by identifying the x,y,z values but it differs. I'm getting different values for iPhone,iPad. Is there any way to find using Accelerometer because I'm using this for background app. UIDeviceOrientation will not work for background app.
Thanks in advance.

Related

Get vertical rotation iphone

I'm developing an app in which I'm getting iPhone's movements.
The iPhone should be taken vertically while the app is running, then I've implemented the accelerometer which helps me to analyze inclination, but I can't study the rotation with it.
So I need to analyze magnetometer rotation, but I don't know if I can use it also if I have the iPhone vertically.
Has anybody already implemented some code for this use?
Thanks!
if (UIInterfaceOrientationIsPortrait([[UIDevice currentDevice] orientation])) {
// device is currently in portrait (vertical) orientation
}
Also, possible duplicate of this : Detect verticality of iPhone

Continue to read iPhone accelerometer data while screen is locked (manually)

I know this issue has been discussed before as in: Enable iPhone accelerometer while screen is locked
I tried the solution mentioned in the post, including adding the DeepSleepPreventer module, as well as enabling proximity sensor as suggested in the answer Enable iPhone accelerometer while screen is locked by adding:
UIDevice *device = [UIDevice currentDevice];
device.proximityMonitoringEnabled = YES;
However, as soon as I manually lock the screen on my iPhone touch, the accelerometer stops sending data. I'm using iOS SDK 4.3. Did I miss anything? Any help would be greatly appreciated.
It's impossible to get accelerometer events on locked ios devices via SDK

About Ambient Light sensor in iphone

Thanks in advance.
I got the information about the iphone sensors from http://ipod.about.com/od/ipodiphonehardwareterms/qt/iphone-sensors.htm. But I didn't get information about how to use ambient sensor in iphone
Here's a link to a description of the ambient light sensor hardware with example code that shows how to access it.
It is possible, and the framework is public.
You can activate the connection to the sensor like so :
[[UIDevice currentDevice] setProximityMonitoringEnabled:YES];
BTW, it doesn't seem to be using the light sensor, because proximity sensing would tweak out in a dark room.
However, the API call basically blanks the screen when you hold the phone up to your face. Not useful for interaction, sadly.
Here is a guide about iPhone sensors :
iPhone sensors

AVFoundation Camera Preview Screen gives wrong zoom

I'm currently developing an app that has a camera functionality, with a custom camera screen, featuring a preview screen and an overlay.
I'm using the AVFoundation classes and methods as per the eradication of UIScreenCapture.
The problem I have is that the preview data I get from AVCaptureSession is too zoomed in. If i take a picture with that screen, and another with the iPhone's default camera app, without moving the iPhone, the difference in zoom is far too much.
I need the zoom of my app to be the same as is default for iPhone camera app.
I've tried changing the AVCaptureVideoPreviewLayer.videoGravity, to any of it's 3 possible values, to no avail.
Please, any leads on this problem are truly appreciated.
Arcantos' solution was mostly correct. That will work assuming you're on an iPhone 3G (or any device with a camera that supports 640x480). An iPhone 4 may run into some issues there.
A more correct way would be to test for the availability of and apply this preset:
captureSession.sessionPreset = AVCaptureSessionPresetPhoto;
This will use the raw camera data, regardless of the native resolution.
Turned out to be a resolution issue.
It was fixed by using
myCaptureSession.sessionPreset = AVCaptureSessionPreset640x480
Note that iPhone 3g does not support that, so you have to ask wheter the device supports it
[[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo] supportsAvCaptureSessionPreset:AVCaptureSessionPreset640x480]
Is the aspect ratio of your preview pane identical to that of the camera capture data? If not, the OS may be changing the zoom to fit the data rect into your requested aspect ratio.

How i customize GPS and Camera setting in my application using objective-C in iphone?

I m the beginner in iphone software development.
I want to make my own customize settings in iphone using objective-C in my own application. In setting UIView i want to perform to set ON/OFF mode of GPS and Camera using UISegment controller/UISwitch.That means i only ON/OFF of GPS and camera setting. I was lot of searching on device setting command(GPS and Camera) using objective-C and now i get frustrate.
You access the GPS system using Core Location. But don't assume it's GPS, because (a) iPod touches and early iPhones don't have GPS, and (b) if the phone is inside a building it may not be able to get a GPS fix.
You turn Core Location on and off using CLLocationManager. Use the startUpdatingLocation and stopUpdatingLocation methods to turn it on and off.