0

iOs 10などの通知を変更しました:

if #available(iOS 10.0, *) {
    let center = UNUserNotificationCenter.current()
    center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in

        let content = UNMutableNotificationContent()

        content.body = notifMessage!
        content.sound = UNNotificationSound.default()
        // Deliver the notification in five seconds.
        let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 5, repeats: false)
        let request = UNNotificationRequest.init(identifier: "Upload", content: content, trigger: trigger)

        // Schedule the notification.
        let center = UNUserNotificationCenter.current()
        center.add(request)
    }
} else {
    let notification = UILocalNotification()
    notification.alertBody = notifMessage
    notification.fireDate = NSDate() as Date
    notification.soundName = UILocalNotificationDefaultSoundName
    UIApplication.shared.scheduleLocalNotification(notification)
}

デバイスを USB に接続してデバイスでアプリを実行すると動作しますが、アプリがバックグラウンドにある場合のみ、次の場合には動作しません。

  • 私はアプリを殺します

  • アプリ表示時

4

2 に答える 2

0

アプリを強制終了すると (ホーム ボタンをダブルタップしてから上にスワイプする)、アプリが終了するだけでなく、アプリのバックグラウンド操作が禁止されます (ユーザーが再度起動するまで)。ホームボタンを押すだけで、通常のメモリ回復プロセスを介してアプリを投棄することができます. または、テスト目的で、プログラムでアプリをクラッシュさせることもできます。ただし、アプリの許容されるバックグラウンド モードに影響するため、スプリングボード (ホーム ボタンのダブル タップ トリック) は使用できません。

アプリが表示されたときの通知、ユーザーが通知をタップした場合、ユーザーが通知を無視して手動でアプリを起動した場合の通知については、これらはすべてさまざまな方法でアプリに伝えられます。ドキュメントの「通知とイベントへの応答」セクションを参照してください。または、バックグラウンド操作に関する一般的な情報については、iOS 用アプリ プログラミング ガイド: バックグラウンド実行を参照してください。UIApplicationDelegate

于 2017-01-16T10:24:15.300 に答える