android - IOS Swift 中的应用类

标签 android ios swift

在 android 中,您可以定义一个类并使用“Application”类进行扩展。在此类中,您可以声明应用程序级别的字段和方法。在此类中,您还可以访问应用程序上下文,并且有一个在应用程序启动时调用的方法。示例如下:

public class App extends Application {

    private static Context sContext;

    private static InterstitialAd mInterstitialAd;

    public static Context getAppContext() {
        return sContext;
    }


    public static InterstitialAd getInterstitialAd() {
        return mInterstitialAd;
    }

    @Override
    public void onCreate() {
        super.onCreate();

        sContext = getApplicationContext();

        MobileAds.initialize(this, sContext.getString(R.string.ADMOB_APP_ID));

        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId(sContext.getString(R.string.interstitial));
        mInterstitialAd.loadAd(new AdRequest.Builder().build());

        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                mInterstitialAd.loadAd(new AdRequest.Builder().build());
            }
        });

    }

}

IOS中对应的东西是什么?

最佳答案

在 iOS 中,您可以使用以下方法在 AppDelegate 文件中进行配置。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
          //Here You Can Configure
            return true
}

关于android - IOS Swift 中的应用类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56109230/

相关文章:

java - 使用我的 Java 库将 Android 应用程序连接到本地 MySQL DB

ios - 在 iOS 上保存和加载客户端证书

ios - 如何使用 View Controller 传回信息

ios - Websockets 可以在手机上运行吗?

objective-c - 使用 ARC 时访问综合属性

swift - 无法在 Swift 4.2 中撤消、重做和再次撤消

ios - 具有 .zero 帧的 View 的位置

android - java.lang.IllegalStateException : Can not perform this action after onSaveInstanceState, FragmentTabHost 问题

android - 我应该将所有 Android View 属性放入样式中吗?

android - Android 有进度条/计时器吗?