ProximityState iPhone Use - iphone

What I would like to do is simply make the iDevice fade the screen to black one the proximityState returns yes. However, I am not sure of how to enable it, or monitor it. Would someone be able to simply provide syntax of enabling and monitoring proximityState?
The help would be highly appreciated for a new programmer like me.
Thanks!
-Jake

You need to use the [UIDevice currentDevice] singleton. First set proximityMonitoringEnabled to YES. Then, you can access the proximity information through the proximityState property. Subscribe to changes to the proximity state by observing the UIDeviceProximityStateDidChangeNotification notification.

Related

Fade To Black When iPhone is Set Face Down

As a new AppDeveloper, I've never used orientation. So, I would like to try to learn with a simple task. What I want to do is have the screen fade to black when the device is set face down. Is that something that would be simple to do, that perhaps somebody could assist me in, or provide helpful information?
Thanks! :D
Your help is appriciated
You can use orientation (using the XYZ values when the screen is face down). I do not recommend this, because your screen will fade out even if a user is using the app while lying down, and staring up at the screen.
There is an easier and cleaner way. Notice how during phone calls, having the phone close to your ear blacks out the screen?
You can access that property by monitoring the proximityState property of UIDevice. Details here
Doing something like:
BOOL closeToUser = [[UIDevice currentDevice] proximityState];
will assign a YES to closeUser when the device is face down on a surface of some kind, and a NO when it is not
If the value is YES, you can invoke code to do whatever you want.

Block external Window (TV-Out) from changing orientation

I'm playing around with the TV-out Adapter for the iphone. My goal is to have an external window display on my tv in order to play movies from my iphone.
the big problem I've got now, is that if the phones orientation changes (physically) the window that shows on the tv turns as well. which is of course unwanted behaviour..
So far i return NO from shouldAutoRotateToInterfaceOrientation. But it still turns and turns.
I'm very grateful for any help on that topic
cheers
sam..
Ah well the solution was rather simple.
I had to assign a RootViewController to the Window that I'm using. Said Rootviewcontroller then needs to implement a shouldAutoRotateToInterfaceOrientation Method (that of course returns NO).

How to detect application préference changes

I created a Settings.bundle in my app where the user can change some properties like font size. It works.
But when I leave my App, and I change my setting, I don't know how I can get notified of the change.
For the moment, I create a function call each time a view is loaded that check for app settings.
But I wonder if there is an other and proper way to do this.
You should use your app delegate's application:didFinishLaunchingWithOptions:, or an equivalent location, to check your NSUserDefaults values, or just read them in a UIViewController viewDidLoad method.
While there is no multi-tasking, this is more than adequate. On MacOS X Cocoa we use KVO and bindings to check for changes during the execution of an application; no doubt something similar will work for 4.0 if required.
I finally found the solution. Like you said Paul, for 4.0 sdk version, there is something similar and I found it in "UIApplicationDelegate protocol".
Thank you for helping me. ;)

Programmatically lock and unlock iPhone screen

How do I programmatically lock and unlock the main screen (i.e. the device itself) of an iPhone?
It's not possible. However, you can "prevent" your phone from locking when your app is running. [UIApplication sharedApplication].idleTimerDisabled = YES should do it.
It can be done by caling GSEventLockDevice (); from your app. This function can be found in GraphicsServices.framework.
This has already been resolved . You can find it on Github: https://github.com/neuroo/LockMeNow (work below IOS 7)
char*framework="/System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices";
void *handle= dlopen(framework, RTLD_NOW);
if (handle)
{
void (*GSEventLockDevice)() = dlsym(handle, "GSEventLockDevice");
if (GSEventLockDevice)
{
GSEventLockDevice();
NSLog(#"Phone is Locked");
//.........
}
dlclose(handle);
}
It is probably possible with undocumented Apple functions (maybe GSEventLockDevice() ?) but it certainly leads to automatic App Store REJECTION.
Apple simply don't want anyone to fiddle with core functionalities like this.
If you want to do this so, Apple never approve this, your app must be jailbreak. you can do this by calling Private framework on your project. you can use GraphicsServices.framework.
NOTE :
This GraphicsServices.framework is a private framework. Apple will never accept your app. By calling GSEventLockDevice() method you can lock or unlock your Device easily. This GSEventLockDevice() resides in the GSEvent.h.
I hope this one helps you.
Please let me know if you still facing any problem
I don't believe that there is a way to achieve this.
One thing that i believe is possible is to stop the IPhone from locking. you could then build a view that copied the lock unlock function and you would still have control over the phone.
it basically isn't possible because this probably is part of the private frameworks which can be used by Apple only. There are apps such as the fake caller apps that utilize a "fake" lockscreen but as you've pointed out, pressing the home button quits the app, rendering your lock screen useless.
Describe lock and unlock. I would try a switch that enabled = YES and enabled = NO for the view property. So basically you can disable all the UIGestureRecognizers and 'lock' the screen, if this is what you mean. I do it with UIbuttons once I add them as an IBOutlet as well as IBAction, so they are an object and can be modified at the property level. I am working on this very thing right now. I will post my findings.

Does UIApplication send a "Shake-to-Edit" notification in iPhone OS 3.0?

In iPhone OS 3.0, UIApplication allows you to set a applicationSupportsShakeToEdit flag. The documentation says "The default value is YES. Set the property to NO if you don’t want your application to display the Undo and Redo buttons when users shake the device."
This is all great and it ties in to the new NSUndoManager class nicely. However - I don't want to use the built in NSUndoManager in my app! I'm writing a drawing app, and I already have an undo/redo manager that does some fancy stuff (it manages the data required for each undo operation, and will page it to disk if the app is low on memory). I'd much rather just listen for a notification from the UIApplication and trigger undo myself. (I could just make a bogus NSUndoManager, but I also don't want the "Are you sure?" panel to show...)
Does anyone know if such a notification exists? I figure it must - but I can't find it documented anywhere. Is there a way to monitor all notifications going through the app, maybe?
Thanks!
You may well have solved this issue by now, but in case someone comes across this searching for a Shake solution as I did I laid out how you can get the 3.0 Shake event messsages easily in this thread:
How do I detect when someone shakes an iPhone?
It outlines how you can respond to shake without using an UndoManager or presenting the Undo API. Even if you set applicationSupportsShakeToEdit to NO, these events will still be received..