Open a Specific View controller when user launch UILocalNotification in ViewBased Application - iphone

I am working with UILocalNotification.Here When i Launch the notification i need a specific view in application.But I have tried like below coding .
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[[UIApplication sharedApplication]setStatusBarHidden:NO];
SplashView *mySplash = [[SplashView alloc] initWithImage:
[UIImage imageNamed:#"Splash.png"]];
[window insertSubview:mySplash atIndex:1];
[window makeKeyAndVisible];
mySplash.delay = 5;
mySplash.animation = SplashViewAnimationFade;
[mySplash startSplash];
[self.window insertSubview:viewController.view atIndex:0];
[self.window makeKeyAndVisible];
[mySplash release];
// Add the view controller's view to the window and display. [self.window addSubview:viewController.view];
UILocalNotification *localNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotification)
{
NSLog(#"Notification Body: %#",localNotification.alertBody);
NSLog(#"%#", localNotification.userInfo);
}
[[UIApplication sharedApplication] cancelAllLocalNotifications];
application.applicationIconBadgeNumber = 0;
return YES;
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateInactive) {
showItemContrller = [[Showitem alloc] initWithNibName:#"Showitem" bundle:nil];
[self.window addSubview:showItemContrller.view];
[self.window bringSubviewToFront:showItemContrller.view];
}
}
But When i launch the notification it is showing the previous view for fraction of seconds the it is going to showItemControllerView.
Thanking you

//comment this line....
//[self.window insertSubview:viewController.view atIndex:0];

Related

How to open another screen instead of Main Screen when push notification received

I need to know how to open another viewcontroller instead of the main view controller when the push notification received please help me thanks in advance here is my code"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
sleep(2);
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
NSUserDefaults* ud = [NSUserDefaults standardUserDefaults];
consumerId = [[ud objectForKey:#"consumerId"] intValue];
couponSql = [[CouponsSqlClass alloc] init];
if (consumerId == 0) {
self.viewController = [[LandingPageViewController alloc] initWithNibName:#"LandingPageViewController" bundle:nil];
self.window.rootViewController = self.viewController;
}
else {
application.applicationIconBadgeNumber = 0;
EditProfileViewController* mainViewController = [[EditProfileViewController alloc] initWithNibName:#"EditProfileViewController" bundle:nil];
_mainViewNavController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
KluebookMenuViewController* leftSideMenuViewController = [[KluebookMenuViewController alloc] initWithNibName:#"KluebookMenuViewController" bundle:nil];
self.deskController = [[IIViewDeckController alloc] initWithCenterViewController:self.mainViewNavController leftViewController:leftSideMenuViewController];
self.deskController.leftLedge = 60;
self.window.rootViewController = self.deskController;
}
[self.window makeKeyAndVisible];
return YES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (launchOptions != nil) {
// Launched from push notification
NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
//Redirect it to your page here
}
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if ( application.applicationState == UIApplicationStateInactive || application.applicationState == UIApplicationStateBackground )
{
//opened from a push notification when the app was on background
//Redirect it to your page here
}
}

Volume Detection In IOS 6

I am creating a app in which when the app is in background and user changes the volume in iPhone app should came to know about it.
Any ideas or clues?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
AudioSessionInitialize(NULL, NULL, NULL, NULL);
AudioSessionSetActive(true);
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(volumeChanged:)
name:#"AVSystemController_SystemVolumeDidChangeNotification"
object:nil];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
LoginVC *login=[[LoginVC alloc]initWithNibName:#"LoginVC" bundle:nil];
self.navigate=[[UINavigationController alloc]initWithRootViewController:login];
[self.window addSubview:navigate.view];
[login release];
[self.window makeKeyAndVisible];
return YES;
}
- (void)volumeChanged:(NSNotification *)notification
{
float volume =
[[[notification userInfo]
objectForKey:#"AVSystemController_AudioVolumeNotificationParameter"]
floatValue];
NSLog(#"chfi");
// Do stuff with volume
}
I Have Used This code But its not getting Called.
You can set a listener. When volume changed, the call back method will be getting called.

I am getting 2 different images in place of splash screen

I am getting an different image at the start of the app like a splash screen then i am getting my actual image that i placed in coding.
I placed the splash screen with the following code in my didFinishLaunchingWithOptions:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.rootViewController = self.tabBarController;
self.tabBarController.delegate=self;
[window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
LoginViewController *vc = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
self.loginNav = [[UINavigationController alloc] initWithRootViewController:vc];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
if([userDefaults valueForKey:#"UserName"] &&[userDefaults valueForKey:#"Password"])
{
vc.username=[userDefaults valueForKey:#"UserName"];
vc.password=[userDefaults valueForKey:#"Password"];
vc.autoLogin=YES;
[vc loginSelectorMethod];
}
else
{
[self.window addSubview:self.loginNav.view];
[self.window makeKeyAndVisible];
}
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashView.image = [UIImage imageNamed:#"splashscreen.png"];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
[self performSelector:#selector(removeSplash) withObject:nil afterDelay:3.0];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
NSLog(#"Registering for remote notifications");
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
return YES;
}
Before the splash screen appears , the "Arrow.png" image appears then my splash screen appers.
If i delete the "Arrow.png" then in place of that image another images appears i.e., "aboutus.png" like that it continues.
I searched in my project for the "Arrow.png" it only appears once in my whole project in the coding.
here you add subiview as a tabbar like bellow..
[window addSubview:tabBarController.view];
after you add loginview like bellow..
[self.window addSubview:self.loginNav.view];
and after that you add splashscreen like bellow..
splashView.image = [UIImage imageNamed:#"splashscreen.png"];
[window addSubview:splashView];
So this is the problem that you seen more then screen instead of splashscreen.
use bellow code...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashView.image = [UIImage imageNamed:#"splashscreen.png"];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
[self performSelector:#selector(removeSplash) withObject:nil afterDelay:3.0];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
NSLog(#"Registering for remote notifications");
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
return YES;
}
and in removeSplash method add this view as a subview of window like bellow..
-(void)removeSplash{
[splashView removeFromSuperView];
LoginViewController *vc = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
self.loginNav = [[UINavigationController alloc] initWithRootViewController:vc];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
if([userDefaults valueForKey:#"UserName"] &&[userDefaults valueForKey:#"Password"])
{
vc.username=[userDefaults valueForKey:#"UserName"];
vc.password=[userDefaults valueForKey:#"Password"];
vc.autoLogin=YES;
[vc loginSelectorMethod];
}
else
{
[self.window addSubview:self.loginNav.view];
[self.window makeKeyAndVisible];
}
}
Have you set any Launch image in ur project setting or have you put any image named "Default.png" in your project bundle this kind of image get detect by OS automatically while launch our app please check this 2 points.
edit:-
Than the problem is conflict in TabBar & LoginView & splaceImage.
For this do below stuff I thing this resolve your double image issue.
First, put below code in your DidFinishLaunching() method
//Delay second that how much time u show your splace image
int64_t delayInSeconds = 5.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
//Do need Full like Add Login View or Add TabbBar
//Remove SplaceImageView From Window
});
splashView = [[UIImageView alloc] initWithFrame:self.window.frame];
splashView.image = [UIImage imageNamed:#"Default-Portrait~ipad.png"];
[self.window addSubview:splashView];
[self.window bringSubviewToFront:splashView];
return YES;
and also one more thing add default splace image like
for iPhone Portrait Default.png.
for iPad, Portrait Default-Portrait~ipad.png
follow as apple document for default image and then check.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
self.sql_ = [SQLDb initEngine];
[self setupControllers]; /// Set up Yor ToolBar Controller
self.hvController = [[HomeViewController alloc] init];
self.window.rootViewController = self.hvController;
[self.window makeKeyAndVisible];
[self setupSplash];
return YES;
}
-(void) setupSplash
{
self.imvSplash = [[UIImageView alloc] initWithFrame:self.window.bounds];
if( IS_IPHONE_5 )
[self.imvSplash setImage: [UIImage imageNamed:#"Default-568h#2x.png"]];
else
[self.imvSplash setImage: [UIImage imageNamed:#"splash.png"]];
[self.window addSubview: self.imvSplash];
[NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:#selector(hideSplash:) userInfo:nil repeats:NO];
}
- (void)hideSplash:(NSTimer *)theTimer
{
[UIView animateWithDuration:1.0
delay:0.1
options: UIViewAnimationCurveEaseOut
animations:^{
self.imvSplash.alpha = 0.0;
self.ngNavigationController.view.alpha = 1.0;
}
completion:^(BOOL finished)
{
//[self.ngController setupImageAction];
[self.imvSplash removeFromSuperview];
}];
}

added subview won't show after the app relaunch

I have a subview added on app relaunch, on the applicationDidBecomeActive got called, but it's not shown, what could be the reason?
- (UIView *)mySubView {
if (_mySubView == nil) {
_mySubView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
_mySubView.opaque = NO;
_mySubView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5f];
_mySubView.exclusiveTouch = YES;
[_mySubView setUserInteractionEnabled:NO];
}
return _mySubView;
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
UIWindow *window = [[[UIApplication sharedApplication] windows] objectAtIndex:0];
[window addSubview:[self mySubView]];
}
What's more interesting is that - it'll shown if I leave the app launched, turn off the device, then turn the device back on. But if I close the app, then relaunch it, I won't be able to see the subview.
Please add the following line like this,
- (void)applicationDidBecomeActive:(UIApplication *)application
{
UIWindow *window = [[[UIApplication sharedApplication] windows] objectAtIndex:0];
[window addSubview:[self mySubView]];
[window makeKeyAndVisible];
}
and also change the color [UIColor blueColor];
You will see the effect sure
Enjoy!
IF you're on your App delegate and you have a window property, as you should have, you could just simply do this:
[[self window] addSubview:[self mySubView]];
For setting the window property do this:
In your AppDelegate.h
#property (strong, nonatomic) UIWindow *window;
In your AppDelegate.m - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
.
.
.
//Create your main controller
.
.
.
[self.window setRootViewController:mainController];
[self.window makeKeyAndVisible];

Correct way to show Login Screen followed by UITabbarController menu

I need to implement the following and I wanted to know the correct way to do it.
when the iPhone application launches, I need to show a logo image for 2 seconds followed by showing a login screen that allows the person to login or create an account. Once the person logs in, i need to show a tabbarcontroller menu options.
This is how I'm currently doing it:
In the AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
LoginViewController *viewController0 = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
UINavigationController *aNavigationController0 = [[UINavigationController alloc] initWithRootViewController:viewController0];
self.window.rootViewController = aNavigationController0;
// I also implement an iVar of the UITabBarController here...
// ....
}
The #implementation:
#implementation LoginViewController
- (IBAction)createNewAccountButtonClicked:(id)sender {
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
delegate.window.rootViewController = delegate.tabBarController;
}
So, my questions are:
Is this the correct way to show the tabbar for my purpose?
In this scheme of things, I cannot show the logo animated. Any pointers on how to do this?
The code below assumes you're using ARC, if you're not then you'll need to do your MRC.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
self.window.rootViewController = self.tabBarController;
LoginViewController *loginViewController= [[LoginViewController alloc] initWithNibName:nil bundle:nil];
loginViewController.delegate = self;
UINavigationController *loginNavCont = [[UINavigationController alloc] initWithRootViewController:loginViewController];
[self.tabBarController presentModalViewController:loginNavCont animated:NO];
UIImageView *splashScreen = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Default"]];
[self.window addSubview:splashScreen];
[UIView animateWithDuration:0.5
delay:2.0
options:0
animations:^{
splashScreen.alpha = 0.0;
}
completion:^(BOOL finished) {
[splashScreen removeFromSuperview];
}];
[self.window makeKeyAndVisible];
return YES;
}
- (void)loginViewControllerShouldBeDismissed:(UIViewController *)viewController
{
[self.tabBarController dismissModalViewControllerAnimated:YES];
}