Prevent iPhone from locking when connected to charger and app is running - iphone

I'm writing an iPhone app. When the app is running and the iPhone is charging, there is no need to lock the iPhone. Is it possible to prevent the locking of the iPhone when the device is charging and my app is running?

You can subscribe to UIDeviceBatteryStateDidChangeNotification notification to get the moment when your iphone begins/stops to charge. Then in case iphone is charging you can set idleTimerDisabled property in UIApplication object to YES to prevent device to go to sleep:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(updateBatteryState:)
name:UIDeviceBatteryStateDidChangeNotification
object:nil];
- (void) updateBatteryState:(NSNotification*)notification{
[UIApplication sharedApplication].idleTimerDisabled =
([UIDevice currentDevice].batteryState == UIDeviceBatteryStateCharging);
}
P.S. If user decides to put device to sleep with sleep/wake button there's no way to prevent him of doing so

This is not possible with current SDK.
EDIT: hmm, haven't got the question correctly from the first read - look on other replies for correct answer; my guess was, you were asking about if it possible to prevent appearance of the sync/charge screen when connecting device via usb or to the wall outlet

Related

Detect lock event on iOS7

Greetings for the Day Everyone!!
I want iOS devices with iOS7 version to detect the lock. I did research a lot in it, but didn't find any solution for iOS7.
For Example,
Programmatically lock iPhone screen in iOS 7
Lock Unlock events iphone
I have implemented the same feature for iOS6 but it is not working for iOS7.
Checkout the working snipppet for iOS6
// coming back in the foreground
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillEnterForegroundNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note)
{
// if user lock the screen
if ([[UIApplication sharedApplication] applicationState] == 1)
{
// coming back after unlocking screen..
}
}];
I have gone through many sources and found there isn't any solution for this in iOS7. Therefor I post the individual question over here, let me know if any one knows how to detect lock event on iOS7 enabled device.
Any help will be appreciated!

Lock iphone home screen from my app

I want to lock the device home screen programatically from my app. Is it possible in IOS?
In my app, if the user is idle for 1 minute, i want to lock the device. This is the scenario.
Thanks
Jithen
you can lock the phone using bellow code
[UIApplication sharedApplication].idleTimerDisabled = YES;
You can lock your own App by Adding a block view on Appdelegate's window. But locking your device is the responsibility of OS. I think if you somehow implement this then still aplle might reject your app on it.

Minimal iOS BluetoothManager Example

I've been constructing a minimal example for detecting nearby Bluetooth devices using the BluetoothManager private framework in iOS 5.0.
Using an answer found in this question: Finding generic Bluetooth devices within reach
Here's my viewDidLoad method to register for the BluetoothAvailabilityChangedNotification. I also register for the BluetoothDeviceDiscoveredNotification as well.
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(bluetoothAvailabilityChanged:)
name:#"BluetoothAvailabilityChangedNotification"
object:nil];
btCont = [BluetoothManager sharedInstance];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(deviceDiscovered:)
name:#"BluetoothDeviceDiscoveredNotification"
object:nil];
When I get the Bluetooth availability changed notification, I set the device scanning enabled, as outlined in one of the answers in the aforementioned link.
- (void)bluetoothAvailabilityChanged:(NSNotification *)notification
{
NSLog(#"BT State: %d", [btCont enabled]);
[btCont setDeviceScanningEnabled:YES];
}
For completeness, here's the deviceDiscovered notification method.
- (void)deviceDiscovered:(NSNotification *) notification
{
NSLog(#"Discovered one!");
}
The logs produced by running the test application are as follows:
BTM: attaching to BTServer
BTM: posting notification BluetoothAvailabilityChangedNotification
BT State: 1
BTM: setting device scanning enabled
Unfortunately, the phone isn't picking up any Bluetooth devices at all, even though I know there are proximate discoverable devices (verified using an Android device).
Some things I have tried already:
Calling [btCont setPowered: YES]; and registering for the associated power state change notification, executing setDeviceScanningEnabled:YES in the callback
Calling [btCont resetDeviceScanning] prior to the setDeviceScanningEnabled call
Calling the scanForConnectableDevices:(unsigned int)arg1; method, guessing that arg1 may be some kind of timeout value. I've tried a variety of values with no success.
Any thoughts would be much appreciated.
Thanks!
As far as I know, the bluetooth manager gets the list after OS has filtered the results.
You will only get the nearby headset devices and not all generic devices.
you have to use scanForServices:
// start scan
[btManager setDeviceScanningEnabled:YES];
[btManager scanForServices:0xFFFFFFFF];

How to detect if user did a screenshot with home+power in iOS?

I'm trying to detect if user take a screenshot in order to warn them this is a video with copyright. I've tried Darwin Notification, but it didn't work...
NSMetadataQuery might be a solution, but we want the app to run on iOS4 as well. Can somebody help me?
Thanks!:p
It is not possible to detect a screenshot has (or will) be taken on iOS 5.
In iOS 4.0, there was a Darwin notification fired PictureWasTakenNotification, but not anymore.
The documentation does not mention anything, and using NSNotificationCenter to subscribe to all notifications only shows silence after taking a screenshot.
before ios 4.0 you can register for PictureWasTakenNotification .This notification is sent when screenshot is taken.No notifications will be sent before the screenshot was taken.
But after that this has been discontinued and IMHO there is no other way round... :/
you can detect it with adding an observer to UIApplicationUserDidTakeScreenshotNotification .
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationUserDidTakeScreenshotNotification
object:nil
queue:mainQueue
usingBlock:^(NSNotification *note) {
// executes after screenshot
}];

How to use iOS 5+ AirPlay for a second screen

I'm toying with AirPlay using an iPhone 4S and I'm having some trouble. I've updated my Apple TV 2 to the latest (4.4.3 I think? I forget, it's in the other room and I'm too lazy to check) and I have iOS 5.0 on my 4S while I use Xcode 4.2 Build 4D199. I wrote a simple UIView app that attempts to draw on a second screen when available. Here's what I have in my viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view addSubview:[[MPVolumeView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]];
NSLog(#"Registering for screen connect events...");
// Do any additional setup after loading the view, typically from a nib.
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(screenDidConnect:)
name:UIScreenDidConnectNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(screenDidDisconnect:)
name:UIScreenDidDisconnectNotification
object:nil]; NSLog(#"There are %i connected screens.", ScreenCount);
if (ScreenCount > 1) {
self.secondWindow = [self myScreenInit:[[UIScreen screens] objectAtIndex:1]];
[self.secondWindow addSubview:[self createFullscreenViewForText:#"Second window" withSize:CGSizeMake(640, 480)]];
}
}
This code works in the simulator when I enable TV Out although it always crashes if I enable TV Out while in debug. I have to relaunch the app after enabling TV out in the hardware menu in the simulator. On relaunch I see the second screen UILabel on the second screen. On the iPhone 4S I can only make this work if I enable AirPlay using the AirPlay control in the running tasks bar all the way to the left. You'll note that I have added an MPVolumeView component to the view on launch which I attempt to use to connect to my Apple TV to no avail.
If I use the in app MPVolumeView I can successfully disconnect from the Apple TV but when I use it again and select the apple TV to reconnect I do not get the UIScreenDidConnectNotification. Again the only time I can see the 2nd screen is when I enable mirroring. If I connect with either AirPlay control I only count 1 screen and never get the notification. Also, each time I enable mirroring I see this in the console logs:
Could not find mapped image ColorOnGrayShadow_AirPlay.png
This seems to be broken and I would like to know what others experience has been in this area. I'll continue to toy around and update this post as I learn new things.
MPVolumeView's route menu can only control an audio stream going to the AppleTV.
Here's a working example of what you are trying to do:
https://github.com/quellish/AirplayDemo/
The "ColorOnGrayShadow_AirPlay.png" log message is normal for iOS 5. Using an Airplay connected AppleTV as an external display unfortunately requires mirroring, and you can't activate that from inside your app. The user has to follow these instructions:
http://support.apple.com/kb/TS4085