If I understand correctly, you want the AppDelegate functionality in the sample to be in your application. But you do not want to replace your AppDelegate application?
The AppDelegate class is actually no different from another class. What makes this fact different is that it implements UIApplicationDelegate and is explicitly mentioned in main.m as the launch class for your application.
If you want to convert this to another class, I would:
- Rename the class names (.h, .m, interface and implementation), and then put them in your project.
- In NewName.h, remove the UIApplicationDelegate implementation at the top.
- In NewName.m you want to look at any of the functions in the UIApplication methods section, since this function is specifically designed to be executed by the AppDelegate class and see how to combine into an existing AppDelegate class. Then remove these UIApplicationDelegate methods from NewName.m, as they can only exist where you implement UIApplicationDelegate.
Since the ViewController exploits the fact that its expected AppDelegate is a long-lived class in the UIApplication hierarchy, you will need to reproduce this behavior. This is probably most easily achieved by creating a new weak property for the NewName link, in ViewController.h:
ViewController.h
@class NewName; @property (nonatomic, weak) NewName *newNameDelegate;
ViewController.m
#import "NewName.h" ... @implementation ViewController @synthesize newNameDelegate; ... - (IBAction)sendRequestButtonAction:(id)sender { if (FBSession.activeSession.isOpen) { [newNameDelegate sendRequest]; } }
NewName.m
... self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; self.viewController.newNameDelegate = self; ...
Hope this gives you an idea of ββwhere to start.
source share