Pass object from VC to App Delegate

2019-08-19 05:52发布

I have a few objects in a VC that I want to be accessible from my App Delegate.

My VC launches another app, which does a callback to my app. This callback triggers a method in my App Delegate:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url

But I want to access some objects in this method that I had set in that previous VC. Any ideas how?

1条回答
手持菜刀,她持情操
2楼-- · 2019-08-19 06:39

Use

+(id)sharedApplicationDelegate; in delegate.h, and write

+(id)sharedApplicationDelegate{
    return  [[UIApplication sharedApplication] delegate];
}

In delegate.m. Make object data type variable in .h and set its property. Write a method like this:

-(void)setObjectForDelegate:(ObjectType *)value{
//use value obj or set it to other variable
}

How to Use:

#import “XXXXdelegate.h”
[[UIApplication sharedApplication] setObjectForDelegate:object];
查看更多
登录 后发表回答