在“设置”中更新了摄像头权限后,UIViewController被关闭

时间:2018-11-01 12:31:09

标签: ios swift permissions camera

如果不允许摄像头访问,并且在更改摄像头权限后关闭用户个人资料页面,则会将用户重定向到“设置”。

UIViewController dismiss after camera permission updated in Settings

  1. 点击“转到设置”选项以更改权限设置
  2. 更改摄像机许可权值后
  3. 在点击状态栏上的上一个应用程序按钮(?)
  4. 当前UIViewController被解雇,并转到先前的UIViewController,即rootViewController

如何预防这种情况?

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

Swift 4.2

  

如果您的应用程序中有表单,并且可能需要权限   更改您的应用程序后,您应该存储和恢复数据。因为你的应用   权限更改后可能重新启动(针对的相机使用权限   例如)。

步骤1:从故事板上的Identity Inspector向您的 def new @colegio = Colegios.new end # GET /colegios/1/edit def edit end # POST /colegios # POST /colegios.json def create @colegio = Colegios.new(colegio_params) respond_to do |format| if @colegio.save format.html { redirect_to @colegio, notice: 'Successfully created.' } format.json { render :show, status: :created, location: @colegio } else format.html { render :new } format.json { render json: @colegio.errors, status: :unprocessable_entity } end end end # PATCH/PUT /colegios/1 # PATCH/PUT /colegios/1.json def update respond_to do |format| if @colegio.update(colegio_params) format.html { redirect_to @colegio, notice: 'Successfully updated.' } format.json { render :show, status: :ok, location: @colegio } else format.html { render :edit } format.json { render json: @colegio.errors, status: :unprocessable_entity } end end end private # Use callbacks to share common setup or constraints between actions. def set_colegio @colegio = Colegio.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. def colegio_params params.require(:colegio).permit(:niños, :niñas, :total_personas) end 添加恢复ID。

步骤2:将这些方法添加到AppDelegate

UIViewController

步骤3:在您的func application(_ application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool { return true } func application(_ application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool { return true } 中覆盖这些方法。您的数据将以UIViewController方法存储。它们将以encodeRestorableState方法恢复。

decodeRestorableState