App Delegate call for Apple Push Notification doesn't present viewcontroller - ios

I have embedded apple push notifications to my app. When a notification is popped, I get an alert view and when clicked on view, I navigate to a Details controller. But, after clicking on the view button, it does not do anything and it freezes the application. Here's my code to open details in alert view click:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
DetailsViewController *list = [[DetailsViewController alloc]initWithNibName:#"Details" bundle:nil];
RearTableViewController *rearView = [[RearTableViewController alloc] init];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:list];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearView];
SWRevealViewController *mainRevealController = [[SWRevealViewController alloc]
initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
mainRevealController.delegate = self;
[self.window.rootViewController presentViewController:mainRevealController animated:YES completion:nil];
[self.window makeKeyAndVisible];
Thanks in advance!

//Don't realloc self.window.
//self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
DetailsViewController *list = [[DetailsViewController alloc]initWithNibName:#"Details" bundle:nil];
//Alloc this VC with nib name like initWithNibNamed:bundle:
RearTableViewController *rearView = [[RearTableViewController alloc]initWithNibName:#"RearTableViewController" bundle:nil];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:list];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearView];
SWRevealViewController *mainRevealController = [[SWRevealViewController alloc]
initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
mainRevealController.delegate = self;
if(self.window.rootViewController){
[self.window.rootViewController presentViewController:mainRevealController animated:YES completion:nil];
}
else{
self.window.rootViewController = mainRevealController;
}
[self.window makeKeyAndVisible];
Hope it will work.

Remove the following code.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
No need to allocate the window once again. If you do so, you have to set the rootViewController again.

Related

How to achieve SplitView Functionality in Portrait mode in iOS?

I'm trying to implement SplitView functionality in my iOS application, it's working fine only in landscape mode in iPad devices.
If I launch or rotate the application from landscape to portrait mode splitView functionality is collapsing.
How to achieve SplitView functionality in iPhone(portrait and landscape) and iPad(Portrait mode) devices?
Please find my codeenter image description here below code.
- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
ViewController *masterViewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
DetailViewController *detailViewController = [[DetailViewController alloc]initWithNibName:#"DetailViewController"
bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
masterViewController.detailViewController = detailViewController;
self.splitViewController = [[CustomSplitViewController alloc]initWithNibName:#"CustomSplitViewController" bundle:nil];
self.splitViewController.viewControllers = #[masterNavigationController, detailNavigationController];
TabBarDetailController *secondVC = [[TabBarDetailController alloc]initWithNibName:#"TabBarDetailController" bundle:nil];
secondVC.tabBarItem.title = #"Second";
ThirdViewController *thirdVC = [[ThirdViewController alloc]initWithNibName:#"ThirdViewController" bundle:nil];
thirdVC.tabBarItem.title = #"Third";
FourthViewController *fourthVC = [[FourthViewController alloc]initWithNibName:#"FourthViewController" bundle:nil];
fourthVC.tabBarItem.title = #"Fourth";
MoreViewController *moreVC = [[MoreViewController alloc]initWithNibName:#"MoreViewController" bundle:nil];
moreVC.tabBarItem.title = #"More";
//make an array containing view controllers
NSArray *viewControllers = [NSArray arrayWithObjects:self.splitViewController,secondVC,thirdVC,fourthVC,moreVC,nil];
[tabBarController setViewControllers:viewControllers];
self.splitViewController.tabBarItem.title = #"HOME";
[self.window addSubview:tabBarController.view];
self.window.rootViewController=tabBarController;
[[self window] makeKeyAndVisible];
return YES;
}
Thanks in advance.

IIViewDeckController is not working when push by navigation controller

Please help me in my project. I am using IIViewDeckController but its not working when pushed by view controller
Heres the hierarchy:
ViewController (Push)----> IIViewDeckController (with Left and centerview).
Here is my code when initialising the IIViewDeckController:
- (IIViewDeckController*)generateControllerStack{
self.navigationView = [[NavigationViewController alloc] initWithNibName:#"NavigationViewController" bundle:nil];
self.profileView = [[ProfileViewController alloc] initWithNibName:#"ProfileViewController" bundle:nil];
UINavigationController* navC = [[UINavigationController alloc] initWithRootViewController:self.profileView];
IIViewDeckController *deckView = [[IIViewDeckController alloc] initWithCenterViewController:navC leftViewController:self.navigationView rightViewController:nil];
deckView.leftSize = 50;
[deckView disablePanOverViewsOfClass:NSClassFromString(#"_UITableViewHeaderFooterContentView")];
return deckView;
}
then this is my code when I'm pushing IIViewDeckController using another ViewController
- (IBAction)signInAction:(id)sender {
IIViewDeckController *deckView = [[UIManager sharedItems] generateControllerStack];
[self.navigationController pushViewController:deckView animated:YES];
}
Thanks you very much guys :)
when I clicked sign in which is I will push my iiviewdeckcontroller with left and centre view this appears
Did you created it like this?
I am using it as root view controller. and it is working fine
UINavigationController* navController=(UINavigationController*)[[UIStoryboard storyboardWithName:#"Main" bundle: nil] instantiateViewControllerWithIdentifier:#"HomeViewController"];
SlideMenuViewController* slide=[[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"SlideMenuViewController"]; /
IIViewDeckController* deckController = [[IIViewDeckController alloc] initWithCenterViewController:navController
leftViewController:slide
rightViewController:nil
topViewController:nil
bottomViewController:nil];
float leftSize=self.window.frame.size.width - (88*self.window.frame.size.width)/320;
deckController.panningMode = IIViewDeckFullViewPanning;
deckController.leftSize =leftSize;
You can do like that.
//Appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController"
bundle:nil];
UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:self.viewController];
self.window.rootViewController = navigation;
[self.window makeKeyAndVisible];
return YES;
}
import IIViewDeckController.h in ViewController.h then
- (IBAction)GoToNext:(id)sender
{
IIViewDeckController *objIIVC = [self.storyboard instantiateViewControllerWithIdentifier:#"Your VC's Identifier"];
[self.navigationController pushViewController:objIIVC animated:YES];
}
Here is my code
- (IIViewDeckController*)generateControllerStack{
self.navigationView = [[NavigationViewController alloc] initWithNibName:#"NavigationViewController" bundle:nil];
UIViewController *centerController = [[ProfileViewController alloc] initWithNibName:#"ProfileViewController" bundle:nil];
centerController = [[UINavigationController alloc] initWithRootViewController:centerController];
self.viewDeck = [[IIViewDeckController alloc] initWithCenterViewController:centerController leftViewController:self.navigationView rightViewController:nil topViewController:nil bottomViewController:nil];
self.viewDeck.leftSize = 50;
[self.viewDeck disablePanOverViewsOfClass:NSClassFromString(#"_UITableViewHeaderFooterContentView")];
return self.viewDeck;
}

App freezes after opening it from an alertView received from a push notification

I have embedded APNS to my app and I navigate to a screen where I have details of the notification. The problem is, when clicked on the view button in the alert view, the app navigates to the .xib file and freezes.
What can I do to workaround this?
Heres the code used to open the viewController xib:
RearTableViewController *rearView = [[RearTableViewController alloc]initWithNibName:#"RearTableViewController" bundle:nil];
DetailsViewController *detailsViewController = [[DetailsViewController alloc]initWithNibName:#"Details" bundle:nil];
detailsViewController.messageID = [[[NSUserDefaults standardUserDefaults] objectForKey:#"messageId"] intValue];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:detailsViewController];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearView];
SWRevealViewController *mainRevealController = [[SWRevealViewController alloc]
initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
mainRevealController.delegate = self;
self.window.rootViewController = mainRevealController;
This may Help you.
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
SplashVC *rootVC = [[SplashVC alloc]initWithNibName:#"SplashVC" bundle:nil];
UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:rootVC];
[navigation setNavigationBarHidden:YES];
self.window.rootViewController = navigation;
[self.window makeKeyAndVisible];
This is my code when i receive push and show alert. If alerts one of the button pressed then this will present my view controller.
LocationViewController *locationVC = [storyboard instantiateViewControllerWithIdentifier:#"LocationVC"];
locationVC.latitude = fLat;
locationVC.longitude = fLong;
[self.navController presentViewController:locationVC animated:YES completion:nil];

tab bar controller can not display view controllers

Here my code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
CSDisplayPlaza *displayPlaza = [[CSDisplayPlaza alloc] initWithNibName:#"CSDisplayPlaza" bundle:nil];
[displayPlaza setTabBarItem:[[UITabBarItem alloc] initWithTitle:#"one" image:[UIImage imageNamed:#"displayPlaza"] tag:0]];
UINavigationController *displayPlazaNav = [[UINavigationController alloc] initWithRootViewController:displayPlaza];
CSGameHall *gameHall = [[CSGameHall alloc] initWithNibName:#"CSGameHall" bundle:nil];
[gameHall setTabBarItem:[[UITabBarItem alloc] initWithTitle:#"two" image:[UIImage imageNamed:#"displayPlaza"] tag:1]];
UINavigationController *gameHallNav = [[UINavigationController alloc] initWithRootViewController:gameHall];
CSMyInformation *myInformation = [[CSMyInformation alloc] initWithNibName:#"CSMyInformation" bundle:nil];
[myInformation setTabBarItem:[[UITabBarItem alloc] initWithTitle:#"three" image:[UIImage imageNamed:#"myInformation"] tag:2]];
UINavigationController *myInformationNav = [[UINavigationController alloc] initWithRootViewController:myInformation];
self.tabBarController = [[UITabBarController alloc] init];
[tabBarController setViewControllers:[NSArray arrayWithObjects:displayPlazaNav,gameHallNav,myInformationNav,nil]];
[tabBarController setSelectedViewController:displayPlazaNav];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
In the simulator, cannot display any view controllers. Just a empty tabbar in my simulator. I don't know what happen.
My guess is displayPlaza is nil for some reason. Add log messages after you create every object to verify you in fact created one, and also the tab bar controllers array.

UITableViewController in UITabBar

I'm trying to create a UITabBarController around my UITableView Controller. I'm using this code. But the problem is that when this is used the Navigation Bar disappears. How do I work around this?
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
StyledTableViewController *viewController1 = [[StyledTableViewController alloc] initWithNibName:#"StyledTableViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[viewController1];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
Need to add UINavigationController to Navigation Bar plus it matain your hierarchy of views
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
StyledTableViewController *viewController1 = [[StyledTableViewController alloc] initWithNibName:#"StyledTableViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:viewController1];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[navController];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;

Resources