Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform Segue in AppDelegate?

I am trying to complete an application on IOS 5.1 with Storyboard. Basically I am doing a dropbox app. Since I am using Dropbox SDK link to Dropbox is handled in AppDelegate.m. User has the option of be able to unlink from a session and link again in different View Controllers. So every time user link and unlinked app has to switch view from Appdelegate to a view controller that is unconnected to rootviewcontroller

In original Dropbox's example Dropbox handled transition like following code

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    if ([[DBSession sharedSession] handleOpenURL:url]) {
        if ([[DBSession sharedSession] isLinked]) {
            [navigationController pushViewController:rootViewController.photoViewController animated:YES];
        }
        return YES;
    }

    return NO;
}

But I am using Storyboard with Navigation Controller and any of the following methods are not working I put methods in comments.

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    if ([[DBSession sharedSession] handleOpenURL:url]) {
        if ([[DBSession sharedSession] isLinked]) {

            NSLog(@"App linked successfully!");
            // At this point you can start making API calls

            /*UIViewController *viewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:NULL] instantiateViewControllerWithIdentifier:@"MeetingViewController"];
            [self.navigationController pushViewController:viewController animated:YES]; */

           //[self performSegueWithIdentifier:@"xxxx" sender:self];

           /* LoginDropboxViewController *loginController=[[LoginDropboxViewController alloc] initWithNibName:@"LoginDropbox" bundle:nil];
            [navigationController pushViewController:loginController animated:YES]; */

        }
        return YES;
    }
    // Add whatever other url handling code your app requires here
    return NO;
}

Here is the storyboard of the app enter image description here

So how can I switch view in AppDelegate.h ?

Note: If I add a segue and name the segue lets say goToMeeting [self performSegueWithIdentifier:@"goToMeeting" sender:self];

error I get is : No Visible @interface for 'AppDelegate' declares the selector performSegueWithIdentifier:sender

like image 636
u.gen Avatar asked Sep 06 '12 17:09

u.gen


People also ask

How do you use segue?

It 's a great segue into the spa lifestyle. Right... erm, there's no easy segue here.

What is perform segue?

How to perform a segue programmatically using performSegue() Swift version: 5.6. Segues are a visual way to connect various components on your storyboard, but sometimes it's important to be able to trigger them programmatically as well as after a user interaction.

What is SceneDelegate and how is it different from a AppDelegate?

AppDelegate is responsible for handling application-level events, like app launch and the SceneDelegate is responsible for scene lifecycle events like scene creation, destruction and state restoration of a UISceneSession.

Is AppDelegate a controller?

The application delegate is a controller object. By default, it is the owner and controller of the main window -- which is a view -- in an iOS app.


1 Answers

If you consider pushing view manually rather then segueperform following code most probably will work for you

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    if ([[DBSession sharedSession] handleOpenURL:url]) {
        if ([[DBSession sharedSession] isLinked]) {

            NSLog(@"App linked successfully!");
            // At this point you can start making API calls

            //push view manually 
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
            LoginDropboxViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"LoginDropbox"];
            [(UINavigationController*)self.window.rootViewController pushViewController:ivc animated:NO];



    }
        return YES;
    }
    // Add whatever other url handling code your app requires here
    return NO;
}
like image 164
Mord Fustang Avatar answered Sep 28 '22 04:09

Mord Fustang