Usage of UIApplication and UIApplicationDelegate

For UIApplicationDelegate

The app delegate performs several crucial roles:

  • It contains your app’s startup code. 

  • It responds to key changes in the state of your app. Specifically, it responds to both temporary interruptions and to changes in the execution state of your app, such as when your app transitions from the foreground to the background.

  • It responds to notifications originating from outside the app, such as remote notifications (also known as push notifications), low-memory warnings, download completion notifications, and more. 

  • It determines whether state preservation and restoration should occur and assists in the preservation and restoration process as needed. 

  • It responds to events that target the app itself and are not specific to your app’s views or view controllers.

  • You can use it to store your app’s central data objects or any content that does not have an owning view controller.

 

For UIApplication

The APIs in this class allow you to manage device-specific behavior. Use your UIApplication object to do the following:

转载于:https://www.cnblogs.com/leyun/p/5317962.html

#import <UIKit/UIKit.h> #import <ReactiveObjC/ReactiveObjC.h> NS_ASSUME_NONNULL_BEGIN #pragma mark - Model @interface StoryScene : NSObject @property (nonatomic, copy) NSString *sceneTitle; @property (nonatomic, copy) NSString *visualDescription; @property (nonatomic, strong) NSArray<NSString *> *symbolicElements; @end @implementation StoryScene @end @interface DigitalTool : NSObject @property (nonatomic, copy) NSString *toolName; @property (nonatomic, copy) NSString *usageDescription; @property (nonatomic, strong) NSArray<NSString *> *appliedScenes; @end @implementation DigitalTool @end @interface InteractionPlan : NSObject @property (nonatomic, copy) NSString *platform; @property (nonatomic, strong) NSArray<NSString *> *engagementMethods; @end @implementation InteractionPlan @end #pragma mark - ViewModel @interface StoryViewModel : NSObject @property (nonatomic, strong) NSArray<StoryScene *> *scenes; @property (nonatomic, strong) RACCommand *loadScenesCommand; @end @implementation StoryViewModel - (instancetype)init { self = [super init]; if (self) { @weakify(self); _loadScenesCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id _) { @strongify(self); return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) { [self fetchScenesFromService]; [subscriber sendCompleted]; return nil; }]; }]; } return self; } - (void)fetchScenesFromService { StoryScene *scene1 = [StoryScene new]; scene1.sceneTitle = @"黑暗中的微光"; scene1.visualDescription = @"黑白基调牢房,霉变米饭特写"; StoryScene *scene2 = [StoryScene new]; scene2.sceneTitle = @"铁窗下的课堂"; scene2.symbolicElements = @[@"树枝笔", @"棉灰墨", @"半截铅笔"]; _scenes = @[scene1, scene2]; } @end @interface ToolViewModel : NSObject @property (nonatomic, strong) NSArray<DigitalTool *> *tools; @property (nonatomic, strong) RACSubject *toolSelectedSubject; @end @implementation ToolViewModel - (instancetype)init { self = [super init]; if (self) { _toolSelectedSubject = [RACSubject subject]; [self setupTools]; } return self; } - (void)setupTools { DigitalTool *tool1 = [DigitalTool new]; tool1.toolName = @"PikaLabs"; tool1.usageDescription = @"水墨晕染风格动画"; DigitalTool *tool2 = [DigitalTool new]; tool2.toolName = @"Runway Gen-3"; tool2.usageDescription = @"动态分镜特效"; _tools = @[tool1, tool2]; } @end #pragma mark - View @interface SceneCell : UICollectionViewCell @property (nonatomic, strong) UILabel *titleLabel; @property (nonatomic, strong) UIImageView *symbolImageView; - (void)configureWithScene:(StoryScene *)scene; @end @implementation SceneCell - (void)configureWithScene:(StoryScene *)scene { _titleLabel.text = scene.sceneTitle; _symbolImageView.image = [UIImage imageNamed:scene.symbolicElements.firstObject]; } @end @interface MainViewController : UIViewController @property (nonatomic, strong) StoryViewModel *storyVM; @property (nonatomic, strong) ToolViewModel *toolVM; @property (nonatomic, strong) UICollectionView *collectionView; @end @implementation MainViewController - (void)viewDidLoad { [super viewDidLoad]; [self setupCollectionView]; [self bindViewModels]; } - (void)setupCollectionView { UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new]; _collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout]; [_collectionView registerClass:SceneCell.class forCellWithReuseIdentifier:@"SceneCell"]; [self.view addSubview:_collectionView]; } - (void)bindViewModels { @weakify(self); [[_storyVM.loadScenesCommand execute:nil] subscribeCompleted:^{ @strongify(self); [self.collectionView reloadData]; }]; [_toolVM.toolSelectedSubject subscribeNext:^(DigitalTool *tool) { NSLog(@"Selected tool: %@", tool.toolName); }]; } #pragma mark - UICollectionViewDataSource - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return _storyVM.scenes.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { SceneCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SceneCell" forIndexPath:indexPath]; [cell configureWithScene:_storyVM.scenes[indexPath.item]]; return cell; } @end #pragma mark - Coordinator @interface AppCoordinator : NSObject @property (nonatomic, strong) UINavigationController *navigationController; - (void)start; @end @implementation AppCoordinator - (void)start { MainViewController *mainVC = [MainViewController new]; mainVC.storyVM = [StoryViewModel new]; mainVC.toolVM = [ToolViewModel new]; _navigationController = [[UINavigationController alloc] initWithRootViewController:mainVC]; } @end #pragma mark - AppDelegate @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (nonatomic, strong) UIWindow *window; @property (nonatomic, strong) AppCoordinator *coordinator; @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { _window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds]; _coordinator = [AppCoordinator new]; [_coordinator start]; _window.rootViewController = _coordinator.navigationController; [_window makeKeyAndVisible]; return YES; } @end NS_ASSUME_NONNULL_END
08-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值