2

I'm a beginner of iOS. We are currently developing it with swift. What I want is to change the wording of the request for permission. It doesn't suit me and I wish I could change this. When the 'Don't Allow' button is pressed in the notification, press the button again and do not request camera permission again. How can I request it?

ViewController.swift

  @IBAction func Onclick(_ sender: Any) {
        AVCaptureDevice.requestAccess(for: AVMediaType.video) { response in
            if response {
                //access granted
            } else {

            }
        }
    }

Current notification statement screen

camera permission function enter image description here

my Info.list

infolist

enter image description here

First of all, I'm sorry that I can't see the picture right away because my score is low.

Thank you in advance.

iosbegindevel
  • 307
  • 5
  • 20
  • I don't think you can change the system notification. A workaround is to show a custom alert _before_ the system alert, telling the user whatever you like, and make the buttons do whatever you like. One of the buttons would then show the system alert. – Sweeper Sep 03 '19 at 08:10
  • Hi @Sweeper Thank you for your help. Then can you redefine the button? Why can't I see a camera request notification when I press the 'Don't Allow' button again? How can I make it look? – iosbegindevel Sep 03 '19 at 08:13
  • You _cannot_ change the behaviour of the system alert buttons. You can show your own alert that has a different behaviour, then show the system alert. – Sweeper Sep 03 '19 at 08:19
  • 1
    It is standard behaviour of all privacy requests - You get once chance to ask. If the user says no, then the system won't ask them again - You can display your own alert but you need to direct them to settings to provide the permission. This to prevent apps from bombarding the user with requests which may make them provide access simply to silence the app. – Paulw11 Sep 03 '19 at 09:08
  • @Paulw11 Can you tell me the example code that lets me go to the alert or setup page when I press the button again? – iosbegindevel Sep 03 '19 at 09:52
  • You would need to check for a `denied` status and show your own alert – Paulw11 Sep 03 '19 at 09:52
  • @Sweeper If you have an example code to execute it, would you please provide it? – iosbegindevel Sep 03 '19 at 09:53
  • @Paulw11 How do I get to the Settings page? If you press the Back button on the Settings page, will you go to my app? – iosbegindevel Sep 03 '19 at 09:55
  • https://stackoverflow.com/questions/46421646/how-to-open-your-app-in-settings-ios-11?r=SearchResults – Paulw11 Sep 03 '19 at 09:57
  • @Paulw11 Thanks you for your help – iosbegindevel Sep 03 '19 at 10:14

3 Answers3

3

Unfortunately you can not customize the text of the buttons or the title of the alert. The only thing you can specify is the message that is displayed, you can set it in your Info.plist file under NSLocationAlwaysAndWhenInUseUsageDescription. As far as I know you actually have to provide this key starting with iOS 11, not only one or the other (when in use or always)

Also, see this answer on how to properly request authorization.

See Apple's documentation here

henrik-dmg
  • 1,448
  • 16
  • 23
  • So how do I get to the settings page when I've already pressed the 'Do Not Allow' button? Can you provide an example code? – iosbegindevel Sep 03 '19 at 09:54
  • You can use this code to open the app's settings page: `UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [:], completionHandler: nil)` – henrik-dmg Sep 03 '19 at 10:48
1

You can't, system alert cannot be customizable (except for the message "I want access the camera") what you can do is show an alert to the user before or after. You can't change the text of the buttons and the alert is showed only once to the user. If the user want to change his choice he needs to do it in the Settings app.

LorenzOliveto
  • 7,796
  • 1
  • 20
  • 47
-1

Of course, You can change the message as whatever you want. just open your Info.plist and change the message:

enter image description here

Quân Hoàng
  • 371
  • 3
  • 9