-1

アプリがアクティブなときにプッシュ通知を受け取ると、表示される UIView を作成します。問題は、ビューが消えることはありませんが、永久にそこにとどまることです。これはコードです:

    func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {

    let rect = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 65)

    let myView = UIView(frame: rect)

    let myViewLabel = UILabel(frame: rect)

    //myViewLabel.text = "Hola"

    myView.addSubview(myViewLabel)

    myView.backgroundColor = .orangeColor()

    if let aps = userInfo["aps"] as? NSDictionary {

        if let alert = aps["alert"] as? NSDictionary {

            if let message = alert["message"] as? NSString {

                //do stuff

            }
        } else if let alert = aps["alert"] as? NSString {

            if application.applicationState == .Active{

                AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))

                myViewLabel.text = alert as String

                self.window?.addSubview(myView)

            }

        }
    }

}

焦点を合わせる

self.window?.addSubview(myView)

それは永遠にそこにとどまります。animateWithDuration のようなことをして 3 秒で非表示にしたいのですが、AppDelegate からそれを行う方法が見つかりません。

何か案が?

4

1 に答える 1