disable automatic locking on iphone with iOS 4.3.3 - iphone

I want to disable the auto lock on my iOS4.3.3 program. I found on the web the same answer several times for this and working for xcode3 but I cant find it to work with mine.. help pls? thks

This should work on iOS 4.3.3. If not then you're doing something wrong:
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];

I did it in a ViewController like this.
-(void) viewDidAppear:(BOOL)animated
{
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
}
-(void) viewDidDisappear:(BOOL)animated
{
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
}

Related

Call the official *Settings* app from my app on iPhone

At one point in my app, I would like to redirect the user to the official Settings app. If possible, I also want go straight to the Network section within the Settings app.
I think what I need is the Settings app's url scheme and the format to construct my request. But I doubt that calling such an official app is forbidden.
Can anyone can help me?
As noted in the comments below, this is no longer possible in iOS version 5.1 and after.
If you are on iOS 5.0, the following applies:
This is now possible in iOS 5 using the 'prefs:' url scheme. It works from a web page or from an app.
example urls:
prefs:root=General
prefs:root=General&path=Network
sample usage:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=General"]]
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=General&path=Network"]]
From IOS 8 you can call the settings from within app with this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
It's also work in iOS version > 5.1, but you must add an URL schemes in URL types in Xcode:
Then you can use
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=WIFI"]];
It's can open system WiFi setting
now.
Other path please find in this answer: iOS Launching Settings -> Restrictions URL Scheme.
Bad news: As #Hlung and #jasongregori suggested, for iDevices whose OS version >= iOS 5.1 && < iOS 8.0, there is once again NO official/documented way to call the built-in Settings app from a third-party app. Period.
Calling the settings app from other app is possible only from iOS 8. So, use the following code
if([CLLocationManager locationServicesEnabled]&&
[CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied)
{
//...Location service is enabled
}
else
{
if([[[UIDevice currentDevice] systemVersion] floatValue]<8.0)
{
UIAlertView* curr1=[[UIAlertView alloc] initWithTitle:#"This app does not have access to Location service" message:#"You can enable access in Settings->Privacy->Location->Location Services" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[curr1 show];
}
else
{
UIAlertView* curr2=[[UIAlertView alloc] initWithTitle:#"This app does not have access to Location service" message:#"You can enable access in Settings->Privacy->Location->Location Services" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"Settings", nil];
curr2.tag=121;
[curr2 show];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag == 121 && buttonIndex == 1)
{
//code for opening settings app in iOS 8
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
}
from iOS 8, you can redirect with
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
enjoy coding
Just an additional answer to add onto the one's addressing iOS8+. If you're supporting anything below 8, you should check to see if it's supported
BOOL canGoToSettings = (UIApplicationOpenSettingsURLString != NULL);
if (canGoToSettings)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
For settings in iOS 9 this is worked for me.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=Settings"]];
But make sure you add a url schemes in URL types in
Info tab in app targets.
For iOS 10 you can use:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"App-Prefs:root=Settings"]];
It is also working on iOS 9!

Is it possible to prevent iphone view from receive touch events? If yes, How?

Is it possible to prevent iphone view from receive touch events? If yes, How?
Try:
yourView.userInteractionEnabled = NO;
You can also try calling
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
to tell your application to ignore touch-related events and
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
to stop ignoring touch-related events.

setApplicationIconBadgeNumber when called multiple times does not update the badge

I am working on an application where in I have to update the badge shown in the app icon multiple times. However, what I have noted is that, the setApplicationIconBadgeNumber api just works once during the lifetime of the app. I have tries using the UILocalNotification, and it works then but, I dont want to follow that route. Have you guys faced a similar problem. If yes, any pointers?
Regards
Nitin
This is a bug in iOS. It's still present today in 6.0.1, where I just fixed it with a work-around:
// Clear app badge number. Work-around for bug in iOS.
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
Might the problem be from where you are calling it?
Wrong:
// This is only called once during application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
Correct:
- (void)applicationWillEnterForeground:(UIApplication *)application {
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}

Calling the appropriate setStatusBarHidden per iOS version

Today my app approved, but I got emails from users says it crash. I figured out that
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation: UIStatusBarAnimationSlide];
Is the problem, Because users have firmware 3.1.x this API is not working and app crash.
So I have replace it with
if ([[[UIDevice currentDevice] systemVersion] floatValue]>=3.2)
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation: UIStatusBarAnimationSlide];
else
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
My questions...
Is what I did the best solution?
Why XCODE did not warn me that SetStatusBarHidden withAnimation is not in 3.0 while I set my Traget OS firmware 3.0?
Do I have to check on every API to see if it is working with my Target OS?
Thank you
I'd recommend you to use the following snipplet of code instead of checking against the version of the os, rather check if a selector is currently available.
if([[UIApplication sharedApplication] respondsToSelector:#selector(setStatusBarHidden: withAnimation:)])
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
else
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
Use only
[[UIApplication sharedApplication] setStatusBarHidden:YES];
instead of
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
It works with no warning
Unfortunately, if you are compiling with the 4.0 SDK using the simulator, the above solutions will give you a warning, which by default is treated as an error:
warning: 'setStatusBarHidden:animated:' is deprecated (declared at /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h:267)
So you can either set 'Treat warnings as errors' to false in the build settings, or you can use macros to conditionally include the correct code. I have my base SDK set to Device 4.0, my target os is 3.1, and am using this macro:
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
#if __IPHONE_OS_VERSION_MIN_REQUIRED > 30100
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:YES];
#else
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
#endif
#endif
Note that setStatusBarHidden:withAnimation came available in 3.2.
That's probably the best thing to do, other than limiting your application to >=3.2. anyways, you xcode should give you a warning that the SetStatusBarHidden withAnimation message is not supported ("may not respond to").

iPhone SDK Quitting

I have found many apps where you can press a button or something similar and the application will terminate and bring you back to the home screen. How would I do this?
exit(0);
this can exit the app .
again, the best way I think will be like as follows:
//#step invoke the normal routine applicationWillTerminate
if ([[UIApplication sharedApplication].delegate respondsToSelector:#selector(applicationWillTerminate:)])
{
[[UIApplication sharedApplication].delegate performSelector:#selector(applicationWillTerminate:) withObject:[UIApplication sharedApplication]];
}
//#step force quite app
kill(getpid(), SIGINT);
I got it from other post on the overflow :D
from http://www.iphonedevsdk.com/forum/iphone-sdk-development/6928-exit-application.html
[[UIApplication sharedApplication] terminateWithSuccess];