2013-10-05 2 views
0

저는 Objective C 놈이고 RubyMotion으로 앱을 만드는 법을 배웁니다.RubyMotion App에서 devise-like "current_user"메소드를 구현합니다.

current_user으로 전화를 걸고 현재 로그인 한 사용자를 내 앱으로 가져오고 싶습니다.

지금은 서버에서 current_user 레코드를 보내고 사용자가 로그인 할 때 User.new (: user)을 호출하지만이 사용자를 전 세계적으로 원하는 방식으로 호출 할 수는 없습니다. Formotion 편집 양식 등으로 보내십시오. MotionModel을 구현해야합니까? 그 도구를 사용하여 즉시 사용할 수있는 current_user 메소드를 얻으려면 어떻게해야합니까?

감사합니다.

답변

1

나는 보통 사용자 모델에서 클래스 메소드를 사용합니다.

User.current_user 

사용자 클래스 :

class User 

    def self.current_user 
    @current_user ||= begin 
     # get your user here, using BubbleWrap's App::Persistence or another persistence mechanism. 
    end 
    end 

end 
0

한 가지 방법은 같은 ID를한다 "initWithId"방법 사용자 세부 컨트롤러는 사용자 정의를 만들 호출 할 때 다음

App::Persistence['currentUserId'] 

그것을 다음, 로그인 응답으로 다시 CURRENT_USER의 ID를 보내 저장하는 것 논증.

UserDetailController.alloc.initWithId(App::Persistence['currentUserId'])