IOS Shared Application hide StatusBar - iphone

I am hiding the Status bar with the below code and it gives me a memory warning level1 . It does nothing to the app itself during the memory warning but I do not like to have such things happening. Is there somthing I am doing wrong? or and con someone confirm a IOS bug? Not a huge deal just bothering me , so any info is greatly appreciated. Thanks!
[[UIApplication sharedApplication] setStatusBarHidden:YES
withAnimation:UIStatusBarAnimationSlide];

Try this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if([[UIApplication sharedApplication] respondsToSelector:#selector(setStatusBarHidden:withAnimation:)]) {
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
}
else {
id<UIApplicationDeprecatedMethods> app = [UIApplication sharedApplication];
[app setStatusBarHidden:YES animated:NO];
}
}
and declare in your .h
#protocol UIApplicationDeprecatedMethods
- (void)setStatusBarHidden:(BOOL)hidden animated:(BOOL)animated;
#end
Hope it helps..

Related

ios 7 document interaction controller hide status bar

In my iOS app i've hidden the status bar with this code in each ViewController:
- (BOOL)prefersStatusBarHidden
{
return YES;
}
In a view I need to use a UIDocumentInteractionController, but when it comes up, the status bar appears, is there a way to keep it hidden?
Thanks in advance
Use a combination of the following code and the code from iOS:
- (UIViewController *) documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *) controller {
// hack to keep status bar visible
[[NSOperationQueue mainQueue] addOperationWithBlock:
^{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}];
return self;
}
combined with
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller {
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
Try this works for me :
- (void)documentInteractionControllerWillBeginPreview:(UIDocumentInteractionController *)controller
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
Set documentController.delegate to self and use
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller {
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}

keywindow is not working in ([[[UIApplication sharedApplication] keyWindow] addSubview:myView];) iOS 6

I am using below code to display a window over movie player controller:
[[[UIApplication sharedApplication] keyWindow] addSubview:myView];
Its working fine in iOS 5 but it stopped working in iOS 6. Even window is not displaying in iOS 6. So please can you suggest me the solution for this.
Thanks
Add [self.window makeKeyAndVisible] to your AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
method and you can use this code
[[[UIApplication sharedApplication] keyWindow] addSubview:view];
to your
- (void)viewDidAppear:(BOOL)animated
method in your ViewController
try this:
[[self window] makeKeyAndVisible];
[[[UIApplication sharedApplication] keyWindow] addSubview:view];
Try it after "appdidFinishLaunching:" finished! May solve it.
[[UIApplication sharedApplication] keyWindow] // available only on main thread

remoteControlReceivedWithEvent not called in multiple view controllers app

I have a App works well on iOS 4.3.3. But I found there are some problems on iOS 5. This App plays mp3 files by avaudioplayer and the remote control does not work well on iOS 5.
There are four view controllers in this App. I add following codes on each view controller in order to realize the function of remote control. The problem is, when the view controller is first time to open. The remote control button works well, even the app run in background or lock the screen. But when I click anther view controller and go back the previous on, the remote controller does not work anymore. But canBecomeFirstResponder function was called every time.
I even try to put
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
in delegate function
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
It not work.
I don't understand why this is happening. It tortured me for few days.
Is there better way to realize remote control function in multiple view controllers?
BTW, I added the UIBackgroundModes audio key to the info.plist. And this App works well well in background.
Any help will be appreciated.
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
- (void)viewWillAppear:(BOOL)animated {
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
}
- (BOOL) canBecomeFirstResponder {
NSLog(#"Can be first responder!");
return YES;
}
- (void)remoteControlReceivedWithEvent:(UIEvent *)event
{
if (event.subtype == UIEventSubtypeRemoteControlTogglePlayPause) {
NSLog(#"UIEventSubtypeRemoteControlTogglePlayPause");
[self playAndpause:nil];
}
}

network activity indicator is not shown on iPhone (iOS 5)

just to test it I enabled the activity indicator of the status bar as follows:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible: TRUE];
//...
}
I never disable the indicator so it should always be visible, but it isn't. It is visible in the iPhone Simulator but not on the device. Why?
Please not that the application is not active when a call is made to didFinishLaunchingWithOptions. You should move this to the viewDidLoad method instead. Thus the code should look like this:
- (void)viewDidLoad {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
// Some other code goes here...
[super viewDidLoad];
}
Or you could put this code anywhere else where the view has been loaded. Do not forget to stop it once the data has been loaded.

How to use [[UIApplication sharedApplication] openURL:] open other app?

I followed http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html instruction to open app1(GlassButton) within app2(FontTest).
The open method of FontTest as following:
-(void)open {
BOOL res = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"glassbutton://"]];
if (res) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"glassbutton://"]];
}
}
The value of "res" is "YES", but nothing happen after openURL method be called.
The info-list of "FontTest"as following:
URL Schemes: glassbutton
URL identifier: com.yourcompany.glassbutton
I tried to open twitter and facebook apps by "twitter://" and "fb://" successfully. But I do not know why I cannot open this small app. I'm not sure whether any thing/step wrong or missing? Need I handle - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url for FontTest, if yes, how to handle it? Could you please kindly help me? Thanks in advance!
To request the launch of your app use something like this:
NSString *urlString= #"glassbutton://com.yourcompany.glassbutton";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
Then, in the glassbutton app, you'll need to handle any special behavior within the app delegate method:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
//your app specific code here for handling the launch
return YES;
}
Note that within the app you are opening the above delegate method will only get called AFTER the following method is called:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Handle accordingly, good luck.