Give a warning to call Apple method

This is a very interesting problem that I have. My application had a problem with presentViewController:animated:completion:and dismissViewControllerAnimated:completion:. It happens that currentViewController is called and based on server information, it is possible that the view manager will be fired. I would get the error message β€œI can’t fire until it’s completely submitted” (the animation is set to β€œYES”).

I queued up the present and rejected the calls. This works just fine and I'm really happy with this solution. Then I realized another problem: what if I accidentally call Apple methods directly (I have a method called myPresentViewController:animated:completion:and myDismissViewControllerAnimated:completion:that processes the queue).

Is there a way to set up a warning method if I directly call Apple methods? I tried to create a category (I also tried the extension), defining Apple and rejecting the methods and adding an obsolete message to them. None of these methods worked. I was thinking of swizzling methods, but this does not work, because if the swizzled method adds it to the queue, how will it know when to call the apple implementation? I understand that a warning will appear in one place where I need to call the Apple method, but I can use #pragma to ban warnings for the two lines that I need.

+4
source share
1 answer

, UIViewController. , . UITableViewController, .

.h.

TGViewController.h

@interface TGViewController : UIViewConrtoller

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion NS_DEPRECATED_IOS(5_0, 6_0);
- (void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^)(void))completion NS_DEPRECATED_IOS(5_0, 6_0);

@end

TGViewController.m

@implementation TGViewController

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion {
    [super presentViewController:viewControllerToPresent animated:flag completion:completion];
}

- (void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^)(void))completion {
    [super dismissControllerAnimated:flag completion:completion];
}

@end

.

, .

+3

Source: https://habr.com/ru/post/1540385/


All Articles