shaheda akter shaheda akter - 3 months ago 15
Objective-C Question

Obj-C How to delay a function in appdelegate.m?

In the appdelegate.m file I want to delay or run this function

[HZInterstitialAd show];
after 10 seconds in this

- (void)applicationDidBecomeActive:(UIApplication *)application
{

}


I am using Xcode version 7.3.1 . Can you please tell me what should I do or What kind of code I have to run

My whole code looks like this now

- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

[HZInterstitialAd show];

}

Answer

This should work:

       [HZInterstitialAd performSelector:@selector(show) withObject:nil afterDelay:10];

Here is the related documentation: https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/#//apple_ref/occ/instm/NSObject/performSelector:withObject:afterDelay: