PM put forward a requirement, start the advertising interface click, directly enter, do not need to flash the main interface.

To this:

Realization of the idea, multi-window mode

A typical AD interface is a mask (subview) above the Key Window.

To push from the AD interface, the natural AD interface is a controller. To enhance the level of advertising interface.

This is promoted to Window. Then switch the displayed window, using the system singleton AppDelegate, [delegate.window makeKeyAndVisible];

If you are using the controller, single window (is the system default created), switch is [UIApplication sharedApplication]. KeyWindow. RootViewController =…

Two considerations:

If you want the home page to load early, you must give the home page a Window container.

If you are using a controller, switching from ads to home page is recreated.

2, can be overused in memory. Home to login, login to the home

The previous project used to switch rootViewController of keyWindow, and then the home page was lost and could not be retrieved. Logon logic, create a new one, feel a little pity. Using multiple Windows, through system singleton (AppDelegate *) UIApplication. SharedApplication. Delegate, back to the home page, you can reuse in memory.


- (void)backToWindow{
    
    AppDelegate * delegate = (AppDelegate *)UIApplication.sharedApplication.delegate;
    [delegate.window makeKeyAndVisible];
}
Copy the code

Three Windows are adopted in the project, one main process, one advertisement, and one login. KeyAndVisible is the advertisement window.


There is no asynchronous downloading of the image to the local first, and save the image name, next time to present.

Here the network request advertising interface to obtain the picture address, and then load the picture. Present immediately. So be sure to put up the AD page first.

How to do?

We’re about to extend the boot time.

Because to wait for a network request (network request advertising interface), failed, enter the main screen. Successful, the image is requested (using two levels of caching)

The extended startup time should not affect the experience or be destroyed by the system daemons. “Trick” is used. The root controller is the advertising controller.

self.adWindow.rootViewController = [[UINavigationController alloc] initWithRootViewController: [[AdvertiseViewController alloc] init]];

The background image of the AD controller, to a placeholder, is the launch map.

It’s a technical downgrade.

(For project reasons, ads are real-time requests. Not an asynchronous cache on the market, use it next time. Huaxin Town Flavor)


@property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) UIWindow *adWindow; @property (strong, nonatomic) UIWindow *loginWindow;Copy the code
@implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary  *)launchOptions { self.window = [[UIWindow alloc] init]; self.window.frame = [UIScreen mainScreen].bounds; FrontTabBarController * tabBarController = [[FrontTabBarController alloc] init]; tabBarController.view.backgroundColor = UIColor.redColor; self.window.rootViewController = tabBarController; self.adWindow = [[UIWindow alloc] init]; self.adWindow.frame = [UIScreen mainScreen].bounds; self.adWindow.rootViewController = [[UINavigationController alloc] initWithRootViewController: [[AdvertiseViewController alloc] init]];; [self.adWindow makeKeyAndVisible];return YES;
}
Copy the code

Matters needing attention:

You need to specify that the Main Interface is empty in the General TAB of Target. It is recommended to delete main.storyboard.

Because you can’t go main.storyboard when you switch Windows on startup.

Disadvantages:

1. No transition. After exiting the AD screen, a swipe brings up the main screen without pop.

Memory management, because the user sees only one Window. After the AD is processed, switch back to the home page window, and release the AD Window. (The AD Window is an appDelegate property, and the appDelegate is a singleton, so the appDelegate AD Window property, when initialized, It will always be there.) At this point write appdelegate.adwindow = nil, it will flash black. This is definitely not going to work. You have to find a place to release it later, the code will be a little messy.


IOS starts the AD interface by adding a sub-view to the window.

    UIWindow *window = [UIApplication sharedApplication].delegate.window;
    [window addSubview: self];
Copy the code

The AD interface is a mask over the rootViewController (or its children) on the home page. When you click on the AD page, it’s usually the content controller pushed by the topViewController on the notification front page.

Search App start to load the page of advertising ideas are written like this. This is a good one.

This idea is quite good. The link of the general advertising interface is a deep link, which strongly interacts with the APP. First load the framework of the whole APP (home page) and enter the world of the business layer.

Generous:

Have a look at the effect of himalaya, also feel very good.

Huaxin town flavor.

Related codes:Dev.tencent.com/u/dengjiang…

Other technical points:

Can network requests asynchronously initiate, next time use, AFNetworking things.

Image caching strategy, SDWebImage thing.

Countdown function, timer. On the picture of advertising interface, add gesture jump.

Unrealized ideas:

(Imagine extending the system startup time, opening a new thread, making network requests, and telling the main thread to continue in its callback. NaN )

IOS start AD page ideas, direct push, home page does not appear, Shanghai Huaxin town flavor

Sorry, I’ll resume it later

Github.com/BoxDengJZ/s…