ios load first page every time the app is opened - ios

is there anyway to make the app load the first page every time it's opened?
It would be nice if some one can help,
Thanks

You can do this with the AppDelegate
Just add code that reloads to the first page.
- (void)applicationWillEnterForeground:(UIApplication *)application
{
/*
Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
*/
}

enter in info.plist app key "Application does not run in background" and put for it value YES

In you app delegate, connect your tabBar to an iVar, and do this:
- (void)applicationWillEnterForeground:(UIApplication *)application
{
self.mayTabBar.selectedIndex=0;
}
This will switch to the first (leftmost) item in the tabBar.

Related

How to show alert when the app is being closed in ios

When my app is running in foreground, If user clicks on home button i want to show some alert like
Do u want to exit the app with Yes/No buttons. Is there any delegate methods called when home button is clicked…
Thank you….
There is no way to do this on iOS. I think you want a similar behavior to Android back button.
Think of iOS home button as Android home button, which doesn't let you prompt user either.
You can not stop the app to go to background, even if you show the alert message, it will go to the background anyways when you hit the home button and you won't see the alert message either.
There is no delegate method that would trigger when the app is going to the background, but there is a delegate method that will trigger when your app has totally gone to background.
Just to show you visually-
In the AppDelegate implementation file(.m), I added an alert message at the end of applicationDidEnterBackground method and put a break point just to check if it is entering that block as I expected. See the result--
You can use these methods in AppDelegate.m
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

Displaying an UIAlertView When A User Unlocks iPhone

I have recently been having some trouble with iOS 7 and unlocking. I am trying to get an UIAlertView to display every time a user unlocks his/her device.
I have gotten the same thing to work with respringing. I am using iOSOpenDev with the logos template. Does anyone know how to achieve an Alert right after unlocking with iOS 7's SBLockscreenViewController, or with something else?
Check out these methods from SBLockScreenViewController:
-(void) prepareForUIUnlock;
-(void) finishUIUnlockFromSource:(int)source;
Both should work fine.
Every time when your application becomes active the following action will be called:
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

What exactly happens with app when user presses home button?

What exactly happens with an app when the user presses the home button? Does iOS make a snapshot of current app's state?
If I'm right, how to "slip in" another snapshot? I need it for showing the main iOS screen after user presses home button twice.
In order to achieve that, you could add a subview (i.e. ImageView with an image of your main screen) to your window in - (void)applicationDidEnterBackground:(UIApplication *)application.
When coming back (in - (void)applicationWillEnterForeground:(UIApplication *)application) you have to remove the subview.
However, Apple recommends to always show the latest state of the app (best user experience).
Example of AppDelegate implementation:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
/* other code */
self.overlayView = [[UIImageView alloc] initWithFrame:self.window.bounds];
self.overlayView.image = [UIImage imageNamed:#"mainscreen_screenshot.png"];
/* other code */
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[self.window addSubview:self.overlayView];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[self.overlayView removeFromSuperview];
}
iOS takes screenshot before your application goes to background.
I got it from Apple's official documentation.
Remove sensitive information from views before moving to the background: When an app transitions to the background, the system takes a snapshot of the app’s main window, which it then presents briefly when transitioning your app back to the foreground. Before returning from your applicationDidEnterBackground: method, you should hide or obscure passwords and other sensitive personal information that might be captured as part of the snapshot.
So, Here We can hide our "sensitive personal information" and the system takes a snapshot of the app’s main window and we are not able to change its feature.
# sensitive personal information
Set a blurry screen overlay before the app goes in the background and once the app becomes active remove this overlay (check #cweinberger's answer).
If it is iOS 7 or later you can use the function ignoreSnapshotOnNextApplicationLaunch
Also, allowScreenShot flag can be explored in Restrictions Payload.
For deeply read about it Then this is the best documentation.

How to make iPhone application go to pause menu when home button is clicked?

I am making an iPhone application that is fairly simple. All I need to do is set the bool "paused" to true to pause the game. How can I make my application do that when the home button is hit?
Thanks guys, that was exactly what I wanted. Since it is in the appDelegate, though, I can't access the boolean "paused" to change it. How can I make it global so that I can access it from the appDelegate?
The Appdelegate.m of your app provides functions you can use to track if the Application will be entering the background;
User pressed the button;
- (void)applicationWillResignActive:(UIApplication *)application
Application is in the background;
- (void)applicationDidEnterBackground:(UIApplication *)application
Within any of these functions you could set the BOOL to True/YES. -> See the comments provided by Apple within the functions for their exact usage.
When the application becomes active again, the appdelegate will (again) fire a function;
- (void)applicationDidBecomeActive:(UIApplication *)application
In your AppDelegate there are two method which is called when the button is called
You can pause the game here:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
//Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
}
or here:
- (void)applicationWillResignActive:(UIApplication *)application{
//Sent when the application is about to move from active to inactive state.
}
In your app delegate, implement applicationWillResignActive:. Set paused = YES; there.
Reset it in applicationDidBecomeActive:.
- (void)applicationWillResignActive:(UIApplication *)application
implement your pause method and it will be called when your app is going to become inactive.

iOS - detect when application exits

How can I detect when a user exits the application? (hitting the home button)
And how can I detect when the relaunch it? (clicking the icon)
*I'm not talking about users manually quitting the app by holding the home button and then making the icons wiggle and deleting the app instance from the sub-dock. i'm talking about just temporarily exiting the app buy clicking the home button.. maybe sending a text or whatnot then coming back to the app.
Thanks!
- (void)applicationDidEnterBackground:(UIApplication *)application
and
- (void)applicationDidBecomeActive:(UIApplication *)application
In your AppDelegate.m
- (void)applicationWillTerminate:(UIApplication *)application
There's a notification UIApplicationDidGoToBackground that fires when the home button is pressed. A similar notification tells you about going back to foreground.

Resources