小编Kar*_*rim的帖子

*** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“线程违规:预期主线程”

我遇到了一个问题,当用户点击个人资料图片将他们的照片上传到应用程序时,我们的应用程序崩溃。应用程序向用户发送授权请求,一旦点击“允许”按钮,就会立即发生崩溃。

也许相关信息是这不是根视图控制器。注册过程在同一个 Storyboard 上有一系列页面。这发生在我需要请求不是主根控制器的权限的任何页面上。

我试图将 PhotoAuthorization 代码块放入 DispatchQueue.main.async,但这似乎不起作用。这是前开发人员的遗留代码,所以我仍在努力修复一些东西。

疑似应用程序崩溃的代码块:

    func checkPermission() {
        let photoAuthStatus = PHPhotoLibrary.authorizationStatus()
        switch photoAuthStatus {
        case .authorized:
            self.showPhotoActionSheet()
        case .notDetermined:
            PHPhotoLibrary.requestAuthorization({ (newStatus) in
                if newStatus == PHAuthorizationStatus.authorized {
                    self.showPhotoActionSheet()
                }
            })
        case .restricted:
            showPermissionRequestReason()
        case .denied:
            showPermissionRequestReason()
        }
    }

    func showPhotoActionSheet() {
        let actionSheet = YoutubeActionController()
        actionSheet.addAction(Action(ActionData(title: "Take Photo", image: UIImage(named: "ic_photo_camera")!), style: .default, handler: { action in 
            if UIImagePickerController.isSourceTypeAvailable(.camera) {
                self.imagePicker.sourceType = .camera
                self.imagePicker.allowsEditing = true
                self.present(self.imagePicker, animated: true, completion: nil)
            }
        })) …
Run Code Online (Sandbox Code Playgroud)

swift ios13

6
推荐指数
1
解决办法
2076
查看次数

如何允许模拟控制器中的本地范围变量来接收消息?

所以,我只用了几天的 Ruby。任何提示将不胜感激。

变量rb

class Variable < ApplicationRecord
  def some_attribute=(value)
    #do something with the vlue
  end
end
Run Code Online (Sandbox Code Playgroud)

X_Controller.rb

class XController < ApplicationController
  def do_something
    variable = Variable.instance_with_id(params[:id])
    variable.some_attribute = some_new_value
    redirect_to(some_url)
  end
end
Run Code Online (Sandbox Code Playgroud)

x_controller_spec.rb

describe '#do_something' do
  before do
    allow(Variable).to receive(:instance_with_id) # Works fine
    allow_any_instance_of(Variable).to receive(:some_attribute)
    
    post :do_something, :params => { id: 'uuid' }, :format => :json 
  end

  it { 
    expect(variable).to have_received(:some_attribute)
  }
end
Run Code Online (Sandbox Code Playgroud)

ruby rspec ruby-on-rails

0
推荐指数
1
解决办法
17
查看次数

标签 统计

ios13 ×1

rspec ×1

ruby ×1

ruby-on-rails ×1

swift ×1