UIApplicationに関して

UIApplicationに関して軽くまとめたいと思います。
 

■UIApplication

UIApplicationクラスは、アプリケーション全体を管理するクラスで、1アプリケーションには必ず1つのUIApplicationが存在します。
 
// UIApplicationの取得方法
UIApplication *app = [UIApplication sharedApplication];
 
 

■UIApplicationのプロパティ

idleTimerDidabled:アプリ起動中に自動スリープにするかどうかの設定(YES:自動スリープOFF、ON:自動フリープ設定)
applicationIconBadgeNumber(数値):アプリアイコンの右上に出す。バッジの設定。
networkActivityIndicatorVisible:ネット使用時に上でぐるぐる〜ってなる設定
 
※ステータスバーの色変更、ステータスバーの表示方法は、プロパティは存在するが、ObjectiveCと同じではないようです。
 
 
 

■ステータスバーの色を変更する方法

プロパティからの設定ではできず、なぜかこの方法で設定できます。

  override func preferredStatusBarStyle() -> UIStatusBarStyle {
        return .LightContent
    }
 
 

■ステータスバーの表示・非表示

プロパティからの設定ではできず、なぜかこの方法で設定できます。 

    override func prefersStatusBarHidden() -> Bool {

        return false
    }
 
 

■ios8でのBadge、Sound、Alertを使用する場合、使用許可確認をする設定が必要

    // ※AppDelegate.swift の起動時に呼ばれる関数
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        UIApplication.sharedApplication().cancelAllLocalNotifications()
        application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.None, categories: nil))
}
 
 
 

■ローカルのプッシュ通知をする方法

    // ※AppDelegate.swift の起動時に呼ばれる関数
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        UIApplication.sharedApplication().cancelAllLocalNotifications()
 
        application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.None, categories: nil))
 
        // 以下が登録処理
        var notification = UILocalNotification()
        notification.fireDate = NSDate(timeIntervalSinceNow: 10)
        notification.timeZone = NSTimeZone.defaultTimeZone()
        notification.alertBody = "通知!!!!"
        notification.alertAction = UILocalNotificationDefaultSoundName
        UIApplication.sharedApplication().scheduleLocalNotification(notification)
        
        return true
    }