如果不允许摄像头访问,并且在更改摄像头权限后关闭用户个人资料页面,则会将用户重定向到“设置”。
UIViewController
被解雇,并转到先前的UIViewController
,即rootViewController 如何预防这种情况?
答案 0 :(得分:1)
看看那个答案:Having app restart itself when it detects change to privacy settings
应用程序重新启动,您无法阻止它。您可以保留和恢复状态:https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/PreservingandRestoringState.html
答案 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