React native IOS pushViewController error only on release build - ios

I have a react native project where I am trying to present a external view controller using React Native iOS Native Modules.
In my AppDelegate, I have instantiated a viewController using storyboard and populating it with react createRootViewWithBridge view.
AppDelegate.mm
UIView *rootView = [self.reactDelegate createRootViewWithBridge:bridge moduleName:#"main" initialProperties:nil];
rootView.backgroundColor = [UIColor whiteColor];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *reactViewController = [storyboard instantiateViewControllerWithIdentifier: #"ReactViewController"];
reactViewController.view = rootView;
UINavigationController *navController = (UINavigationController*)[storyboard
instantiateViewControllerWithIdentifier: #"UINavigationController"];
[navController pushViewController:viewController animated:YES];
self.navController = navController;
self.window.rootViewController = navController;
[self.window makeKeyAndVisible]; [super application:application didFinishLaunchingWithOptions:launchOptions];
return YES;
I have a IOS native module that I call using from my react Side:
Homescreen.tsx
SdkModule.openPendingAuthorization(
RAS_USER_ID,
RAS_CLIENT_ID,
RAS_CLIENT_SECRET,
RAS_URL
)
And then in my native module method, I am pushing the viewcontroller into the navigation controller.
RCTSdkModule.m
RCT_EXPORT_METHOD(openPendingAuthorization:(NSString *)userId
clientId:(NSString *)clientId
clientSecret:(NSString *)clientSecret
url:(NSString *)url)
{
Data *obj=[Data getInstance];
obj.userId = userId;
obj.clientId = clientId;
obj.clientSecret = clientSecret;
obj.url = url;
dispatch_async(dispatch_get_main_queue(), ^{
UIApplication *app = [UIApplication sharedApplication];
UINavigationController *nav = (UINavigationController *) app.delegate.window.rootViewController;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier: #"SdkViewController"];
[nav pushViewController:viewController animated:YES];
});
}
And then, I am able to run the SDK code in viewcontroller related to SDK:
SdkViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
// SDK Related Code
}
My code runs fine when I run it as DEBUG build in XCode. But, if I switch to Release build or, Create ipa using eas build, it gives me the following error.
`unrecognized selector sent to instance-pushviewcontrolleranimated
It seems that, in [nav pushViewController:viewController animated:YES] , the nav is a viewController, not a UINavigationController. But it does not give the error in Debug mode.

Related

How to set Root View Controller programatically in Objective C?

I am a newbie in iOS Development trying to learn how to create and set views programmatically.
i am trying to do swift statement in Obj-C
window?.rootViewController = UINavigationController(rootViewController : ViewController())
Project: Single View Application . Trying to link default Created ViewController.h
As per Krunals Answer i updated code but Navigation Controller is not shown in simulator
Cmd+Click on controller does not navigate to ViewController File
#import "AppDelegate.h"
#import "ViewController.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIScreen *screen=[[UIScreen alloc]init];
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.makeKeyAndVisible;
ViewController *controller = [[ViewController alloc] init];
window.rootViewController = [[UINavigationController alloc] initWithRootViewController:controller] ;
Initialise your view controller ViewController before you add (use as root controller of navigation) into navigation controller stack.
Here is sample code to initialise simple view controller
UIViewController *controller = [[UIViewController alloc] init];
Here is sample code to initialise using storyboard
ViewController *controller = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"<ViewController - string identifier of your view controller>"];
Here is sample code to initialise using NIB/Bundle
ViewController *controller = [[ViewController alloc] initWithNibName:#"<ViewController - string NIB name>>" bundle:nil];
According to your code and following comment try this code only (remove other codes from your app delegate launch):
// make sure your NIB name is 'ViewController'
ViewController *controller = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
if (controller != nil) {
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController: controller];
self.window.makeKeyAndVisible;
} else {
//print - your view controller is nil
}
Thanks to Krunal for detailed answer .
Thanks to dan for support
i found issue instead of self.window.rootViewController , i typed window.rootViewController.
setting self.window.rootViewController solved issue.
i dont know difference between self.window.rootViewController and window.rootViewController and reason for issue.
If some one knows answer please provide answer on comment
#import "AppDelegate.h"
#import "ViewController.h"
#interface AppDelegate ()
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UIScreen *screen=[[UIScreen alloc]init];
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.makeKeyAndVisible;
ViewController *controller = [[ViewController alloc] init];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:controller] ;
Delele the file Main.storyboard and let the Main interface option empty before you do it.
And add this code:
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
ViewController *vc = [[ViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
UPDATE: If you want to use storyboard with UINavigationController, try this:
Adding UIViewController and adding with UINavigationController
UIStoryboard *storyboard = self.window.rootViewController.storyboard;
UIViewController *rootViewController= [storyboard instantiateViewControllerWithIdentifier:kIdentifier];
[self setRootViewController:rootViewController];
#pragma mark - Set RootView Controller
-(void)setRootViewController:(UIViewController *)rootViewController {
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
}
UIStoryboard *storyboard = self.window.rootViewController.storyboard;
UIViewController *rootViewController= [storyboard instantiateViewControllerWithIdentifier:kIdentifier];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[self setRootViewController:navController];
-(void)setRootViewController:(UINavigationController *)rootViewController {
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
}

App shows black screen in iOS

I am developing iOS app in which i have side menu with TabBar,
I have settled My sidemenu container viewController as IntitalViewController of my app.
Here is my code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
MFSideMenuContainerViewController *container = (MFSideMenuContainerViewController *)self.window.rootViewController;
UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:#"navigationController"];
UIViewController *leftSideMenuViewController = [storyboard instantiateViewControllerWithIdentifier:#"leftSideMenuViewController"];
[container setLeftMenuViewController:leftSideMenuViewController];
[container setCenterViewController:navigationController];
return YES;
}
Here is the Design of my Storybaord:
When i run my app i see a black screen with no error
Where i am making mistake, please help
Thanks in adavnnce !!
Give try to this (after seeing your code):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
self.window.rootViewController=[[MFSideMenuContainerViewController alloc]init];
// Override point for customization after application launch.
MFSideMenuContainerViewController *container = (MFSideMenuContainerViewController *)self.window.rootViewController;
UITabBarController *tabController = [storyboard instantiateViewControllerWithIdentifier:#"tabBarController"];
UIViewController *leftSideMenuViewController = [storyboard instantiateViewControllerWithIdentifier:#"leftSideMenuViewController"];
[container setLeftMenuViewController:leftSideMenuViewController];
[container setCenterViewController:tabController];
[self.window makeKeyAndVisible];
return YES;
}
Also give the respective id's to view controllers in storyboard ( for tabBar, navigation)
and don't forget to give root view controller for navigation
controller.

Screen black out issue with JASidePanel

I tried to integrate the JASidePanel in my app. Below is my code for initialising JSSidePanel controller.
- (void)viewDidLoad {
[super viewDidLoad];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main"
bundle: nil];
UIWindow *window= [UIApplication sharedApplication].keyWindow;
self.viewController = [[JASidePanelController alloc] init];
self.viewController.shouldDelegateAutorotateToVisiblePanel = NO;
self.viewController.leftPanel = [mainStoryboard instantiateViewControllerWithIdentifier:#"BBWSideMenuViewController"];
self.viewController.centerPanel = [self.navigationController.viewControllers lastObject];
window.rootViewController = self.navigationController;
[window makeKeyAndVisible];
}
Button Action method,
- (IBAction)openSideMenu:(id)sender {
[self.viewController showLeftPanelAnimated:YES];
}
When I'm pressing button to open side menu, entire screen is getting black. How may i fix this?. Any Help will be much appreciated.

Presenting ViewController from appDelegate

I need to show a ViewController from the appDelegate every time the app comes from the background in the applicationDidEnterBackground method.
The *securityCheck prompts the user for a passcode very much like the normal passcode in iOS. Once the passcode is validated I call dimissViewControllerAnimated inside the securityCheck and I am left with my blank UINavigationController, since the view was presented from the appDelegate I have no record of who presented the view, so I can't popToRootViewController.
My question is how can I properly dismiss the SecurityCheckViewController so that it shows the ViewController which the user was on before the app entered the background.
Here's my code:
This method is called inside AppDelegate.m
- (void)securityCheck {
SecurityCheckViewController *securityCheck = [[SecurityCheckViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:securityCheck];
[securityCheck presentedByAppDelegate:YES];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:navigationController];
[self.window makeKeyAndVisible];
}
Then inside the SecurityCheckViewController.m I have
- (void)unlockWasSuccessfulForPadLockScreenViewController:(ABPadLockScreenViewController *)padLockScreenViewController {
[self.appDelegate securityCheckDone];
[padLockScreenViewController dismissViewControllerAnimated:YES completion:nil];
NSLog(#"Sucsessfull Unlock");I'm
}
Present
- (void)securityCheck {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil];
SecurityCheckViewController *securityCheck = [storyboard instantiateViewControllerWithIdentifier:#"securityCheckView"];
[self.window.rootViewController presentViewController:securityCheck animated:NO completion:nil];
}
Dismiss
[self dismissViewControllerAnimated:YES completion:nil];
You can call this from application:didFinishLaunchingWithOptions
NOTE: All the storyBoard "initialViewControllers" tick box on the property inspector is turned off
UIStoryboard *storyboard =
[UIStoryboard storyboardWithName:#"Registration" bundle:nil];
RegisterViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"RegisterViewController"];
//this is key else you get a black screen
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];

I try to pushViewController but i cant

I try to push Viewcontroller it doesn't work.
AppDelegate.m (I import ViewController to use it as rootView)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
ViewController *view = [[ViewController alloc]init];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:view];
return YES;
}
Next is my Viewcontroller.m
-(void)goToView{
ViewController2 *view2 = [[ViewController2 alloc]initWithNibName:#"newView" bundle:nil];
[self.navigationController pushViewController:view2 animated:YES];
}
I got error message:
Cannot find executable for CFBundle 0x8f9bd80</Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.p‌​latform/Developer/SDKs/iPhoneSimulator7.1.sdk/System/Library/AccessibilityBundles‌​/CertUIFramework.axbundle>(not loaded)
2014-07-11 17:10:47.372 pushTest[2007:60b]***Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/home/Library/Application Support/iPhone Simulator/7.1/Applications/0D78CE53-F02B-467F-8250-8D2D3639A301/sta.app> (loaded)'with name 'newView'
This error can occure when you rename some files outside XCode. To solve it you can just remove the files from your project (Right Click - Delete and "Remove Reference") You re-import the files in your project and everything will be ok !
another choice
in your error code Could not load NIB in bundle means
ViewController2 *view2 = [[ViewController2 alloc]initWithNibName:#"newView" bundle:nil];
the Name newView does not match with bundle
just use this
ViewController2 *vc2 = [[ViewController2 alloc] init];
[self.navigationController pushViewController:vc2 animated:YES];
in your app delegate.m add the valid Navigation controller
try this Navigation Controller Push View Controller
try this:
in AppDelegate
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
RootViewController *rvc = [mainStoryboard instantiateViewControllerWithIdentifier:#"RootViewController"];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:rvc];
self.window.rootViewController = nc;
in your Storyboard add a new ViewController with the storyBoard Identifier: "RootViewController".
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
UINavigationController *navc = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navc;
[_window addSubview:navc.view];
[self.window makeKeyAndVisible];
return YES;
}
Hope it helps.

Resources