Get vertical rotation iphone - 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

Related

Find device orientation using Accelerometer data x,z,y

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.

cocos2D from iPhone to iPad

I'm developing a game using cocos2d. It's running now on iPhone and also supports Retina display. With retina i'm using images with "-hd" postfix. Now i want my application to be able to work on iPad using this images. How can i do that ?
PS: I don't have a real iPad and can only use a simulator. I will test the game on my friend's iPad after it will work well on a simulator. Is it possible to use hi-res images with simulator and how to do it?
I'm using cocos2D 0.99.5
inside CCFileUtils.m
inside method name +(NSString*) getDoubleResolutionImage:(NSString*)path
edit if( CC_CONTENT_SCALE_FACTOR() == 2)
to if( CC_CONTENT_SCALE_FACTOR() == 2 || (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad))
this will make the app to load the -hd image when running on ipad, remember to change your app targeted device family to iPhone/iPad.
this will solve the loading of -hd problem for ipad.
but after loading -hd file for ipad resolution, you will also notice that most of your image position should be off alignment, now either you go directly into the cocos2d folder to edit how CCNode,CCSprite,CClabel handle the positioning of thing or you code it in your code checking if its ipad or not.
if you are using CCSpriteBatchNote. this will also cause another problem because you will be reading from the -hd SpriteSheet. so the texture Rect u set to cut need to be double too.
another method is position everything according to winsize. i haven try this method.
I don't exactly understand the question but I will try to answer.
You can technically use the same graphics for the iPad, but they will not look as nice. For one, they will all blurry and pixelated, and two, the iPad has a different screen aspect ratio that the iPhone/iPod Touch. If you do make separate images for an iPad version of your game, it will not be extremely difficult to do. If you want to do this, I suggest posting a new question.

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.

UIImagePickerController on iPhone 4 device

This is no typical programming question.
I am currently developing an app using the latest SDK. This app will use the UIImagePickerController for taking pictures with the built-in camera.
I know the new iPhone 4 has 2 cameras built in. But the simulator doesn't support the camera in any way, so there's is now way to test the camera controller on a new iPhone. I do have a iPhone 3G to test my app with.
But what I want to know now, if someone can provide me a screenshot of the UIImagePickerController in camera mode running on his iPhone 4? But I really need an image from the UIImagePickerController not from the common camera application on the iPhone, because those two image pickers aren't the same! I can see this on my iPhone 3G: the built-in camera application and the UIImagePickerController are having a totally different UI.
Why I am asking for that? Because I want to know if there is a built-in switch in UIImagePickerController to switch between the front and rear camera. I know there is such a switch if you want to take a picture using the common iPhone 4 camera application, but I don't know if this switch also exists in UIImagePickerController from the SDK.
Thanks for your help!
C YA
Here you go. I managed to catch it with the zoom control and focus square.

Can I prevent mobile safari from auto-rotating the screen on ipod touch or iphone?

We have an offline Safari application with UI designed for vertical use (pixel perfect). We would like the UI to stay vertical no matter what how the user rotates the ipod / iphone. Is it possible with offline Safari application?
This question is exactly the same as Can I prevent mobile safari from auto-rotating the screen on ipod touch or iphone? . Yet - the referenced question has no definite answer and has been prematurely accepted.
I'm not aware of any way to prevent the rotation if it needs to run in Safari rather than a native app with an embedded UIWebView.
While you can't prevent the rotation, you can compensate for it like this:
Detect the rotation using the updateorientation event
In your event handler, find the current orientation using window.orientation. (e.g. 0, 90, -90, 180)
Update the class of your element to reflect the current orientation, and use styles like -webkit-transform:rotate(-90deg) to rotate your UI in the opposite direction.
If necessary, use window.scrollTo(0, 1); to scroll the address bar off the screen.