別のviewControllerからのアクセス許可(リモート通知とローカル通知、カメラとオーディオ)をユーザーに尋ねたいと思います。ビューコントローラはオンボーディングプロセス中に提示され、再度は表示されません。iOS 10/Swift 3でリモート許可を求める方法
リモート通知をAppDelegateの外部に表示するにはどうすればよいですか? 私の質問は、それらを起動する方法ではなく、AppDelegateが権限を与えられた後にそれらを処理するための "責任"があることを確認する方法です。私は許可
import UIKit
import UserNotifications
class AskForNotificationPermissionVC: UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
requestPermissions { (videoGranted, audioGranted, notificationsGranted) in
if videoGranted && audioGranted && notificationsGranted {
DispatchQueue.main.async{
self.performSegue(withIdentifier: "toPaySegue", sender: self)
}
} else {
DispatchQueue.main.async{
self.presentSpecialPopoup()
}
}
}
}
func requestPermissions (completion: @escaping ((Bool, Bool, Bool)->())) {
let center = UNUserNotificationCenter.current()
center.delegate = UIApplication.shared.delegate as! UNUserNotificationCenterDelegate?
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (videoGranted: Bool) -> Void in
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeAudio, completionHandler: { (audioGranted: Bool) -> Void in
center.requestAuthorization(options: [.alert, .badge, .sound]) { (notificationGranted:Bool, error) -> Void in
UIApplication.shared.registerForRemoteNotifications()
completion(videoGranted, audioGranted, notificationGranted)
}
})
})
}
}
どれでも助けを求めるAppDelegate
import UIKit
import UserNotifications
import PushKit
import CallKit
AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, UNUserNotificationCenterDelegate {
let pushRegistry = PKPushRegistry(queue: DispatchQueue.main)
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
pushRegistry.delegate = self
pushRegistry.desiredPushTypes = [.voIP]
....
}
のViewControllerで
現在のコードは非常に、非常に高く評価されます!ありがとうございました。
ヘルパーは混乱しているようです。より詳細な問題を説明してください。あなたのコードを使って実際に何が起こっていますか?そして、あなたは何を達成したいのですか? – shallowThought