Skip to content

Commit

Permalink
Added option to customize showDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
vdeep committed Jun 20, 2019
1 parent 91a2d98 commit 09241b2
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
FMPhotoPickerExample/FMPhotoPickerExample.xcodeproj/project.xcworkspace/xcuserdata/
FMPhotoPickerExample/FMPhotoPickerExample.xcodeproj/xcuserdata/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,24 @@ public class FMPhotoPickerViewController: UIViewController {
if Helper.canAccessPhotoLib() {
self.fetchPhotos()
} else {
Helper.showDialog(in: self, ok: {
Helper.requestAuthorizationForPhotoAccess(authorized: self.fetchPhotos, rejected: Helper.openIphoneSetting)
})
let okAction = UIAlertAction(
title: config.strings["permission_button_ok"],
style: .default) { (_) in
Helper.requestAuthorizationForPhotoAccess(authorized: self.fetchPhotos, rejected: Helper.openIphoneSetting)
}

let cancelAction = UIAlertAction(
title: config.strings["permission_button_cancel"],
style: .cancel,
handler: nil)

Helper.showDialog(
in: self,
okAction: okAction,
cancelAction: cancelAction,
title: config.strings["permission_dialog_title"],
message: config.strings["permission_dialog_message"]
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public struct FMPhotoPickerConfig {
"editor_crop_ratioCustom": "Custom",
"editor_crop_ratioOrigin": "Origin",
"editor_crop_ratioSquare": "Square",

"permission_dialog_title": "FMPhotoPicker",
"permission_dialog_message": "FMPhotoPicker wants to access Photo Library",
"permission_button_ok": "OK",
"permission_button_cancel": "Cancel"
]

public init() {
Expand Down
12 changes: 6 additions & 6 deletions FMPhotoPicker/FMPhotoPicker/source/Utilities/Helper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ class Helper: NSObject {
}

static func showDialog(in viewController: UIViewController,
ok: (() -> Void)? = nil,
cancel: (() -> Void)? = nil,
title: String = "FMPhotoPicker",
message: String = "FMPhotoPicker want to access Photo Library") {
okAction: UIAlertAction = UIAlertAction(title: "OK", style: .default, handler: nil),
cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil),
title: String? = "FMPhotoPicker",
message: String? = "FMPhotoPicker want to access Photo Library") {
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)

alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: { _ in ok?() }))
alertController.addAction(UIAlertAction(title: "キャンセル", style: .cancel, handler: { _ in cancel?() }))
alertController.addAction(okAction)
alertController.addAction(cancelAction)

viewController.present(alertController, animated: true)
}
Expand Down

0 comments on commit 09241b2

Please sign in to comment.