Skip to content

Commit

Permalink
[fix] 알림, 위치정보 설정 클릭 시 설정앱으로 (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
trumanfromkorea committed Dec 12, 2022
1 parent 6a931df commit 8b83b14
Showing 1 changed file with 18 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,27 @@ final class ProfileViewController: UIViewController, BaseViewController {
}

func bind() {
guard let viewModel else {
return
}

profileView.notificationButton.rx.tap
.bind {
viewModel.input.tapSetupNotification.onNext(())
.bind { [weak self] in
self?.viewModel?.input.tapSetupNotification.onNext(())
}
.disposed(by: disposeBag)

profileView.settingButton.rx.tap
.bind {
viewModel.input.tapSetting.onNext(())
.bind { [weak self] in
self?.viewModel?.input.tapSetting.onNext(())
}
.disposed(by: disposeBag)

profileView.signOutButton.rx.tap
.bind {
viewModel.input.tapSignOut.onNext(())
.bind { [weak self] in
self?.viewModel?.input.tapSignOut.onNext(())
}
.disposed(by: disposeBag)

profileView.deleteAccountButton.rx.tap
.bind {
viewModel.input.tapWithdrawal.onNext(())
.bind { [weak self] in
self?.viewModel?.input.tapWithdrawal.onNext(())
}
.disposed(by: disposeBag)

Expand All @@ -77,28 +73,18 @@ final class ProfileViewController: UIViewController, BaseViewController {
guard let viewModel else {
return
}

viewModel.input.tapSetupNotification
.withUnretained(self)
.bind { owner, _ in
NotificationManager.shared.checkNotificationAuthorization { isAuthorized in
if isAuthorized {
owner.showAlreadyAllowed(type: .notification)
} else {
owner.showRequestAuthorization(type: .notification)
}
}
owner.showSettings(type: UIApplication.openNotificationSettingsURLString)
}
.disposed(by: disposeBag)

viewModel.input.tapSetting
.withUnretained(self)
.bind { owner, _ in
LocationManager.shared.checkLocationAuthorization { isAuthorized in
if isAuthorized {
owner.showAlreadyAllowed(type: .location)
} else {
owner.showRequestAuthorization(type: .location)
}
}
owner.showSettings(type: UIApplication.openSettingsURLString)
}
.disposed(by: disposeBag)

Expand Down Expand Up @@ -138,29 +124,12 @@ final class ProfileViewController: UIViewController, BaseViewController {
alertController.addAction(acceptAction)
present(alertController, animated: true, completion: nil)
}

private func showAlreadyAllowed(type: Authorization) {
let alertController = UIAlertController(title: type.description, message: "이미 동의하셨습니다.", preferredStyle: .alert)
let acceptAction = UIAlertAction(title: "확인", style: .default, handler: nil)
alertController.addAction(acceptAction)
DispatchQueue.main.async { [weak self] in
self?.present(alertController, animated: true, completion: nil)
}
}

private func showRequestAuthorization(type: Authorization) {
guard let url = URL(string: UIApplication.openSettingsURLString) else {
return
}
let alertController = UIAlertController(title: type.description, message: "앱 설정에서 \(type.description)을 허용해주세요.", preferredStyle: .alert)
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
let acceptAction = UIAlertAction(title: "OK", style: .default, handler: { _ in
UIApplication.shared.open(url)
})
alertController.addAction(cancelAction)
alertController.addAction(acceptAction)
DispatchQueue.main.async { [weak self] in
self?.present(alertController, animated: true, completion: nil)

private func showSettings(type: String) {
guard let url = URL(string: type) else {
return
}

UIApplication.shared.open(url)
}
}

0 comments on commit 8b83b14

Please sign in to comment.