【问题标题】:Application Class in IOS SwiftIOS Swift 中的应用程序类
【发布时间】:2019-09-30 05:31:21
【问题描述】:

在 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中对应的东西是什么?

【问题讨论】:

  • 显示你的一些代码你为得到想要的结果所做的工作
  • wings,android代码还是ios代码?
  • 两者都可以显示,但要标明是安卓还是iOS
  • wings,我无法显示 ios 代码,因为这正是我需要的。对应的IOS代码。

标签: android ios swift


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    您可以在 iOS 的单独文件中定义类级别的方法,您可以在 AppDelegate 文件的 didFinishLaunchingWithOptions() 中调用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-24
      • 2015-04-05
      • 1970-01-01
      • 2015-04-02
      • 2015-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多