푸시 알림이있는 iPhone 앱을 만들고 있습니다. 내 질문은 클래스 B의 인스턴스를 만들지 않고 정적 알림을 사용하지 않고 푸시 알림을 받으면 클래스 B에서 함수를 호출하는 방법입니다.푸시 알림을받을 때 함수를 호출하는 방법은 무엇입니까?
많은 감사합니다 :)
푸시 알림이있는 iPhone 앱을 만들고 있습니다. 내 질문은 클래스 B의 인스턴스를 만들지 않고 정적 알림을 사용하지 않고 푸시 알림을 받으면 클래스 B에서 함수를 호출하는 방법입니다.푸시 알림을받을 때 함수를 호출하는 방법은 무엇입니까?
많은 감사합니다 :)
당신은 푸시 알림 수신 객체 내에서 ClassB가에 대한 참조를 유지해야합니다 당신은 분명히 작동하기 전에이 클래스에서 classB
의 인스턴스를 설정해야합니다
// The header file of the class that receives the notification
@class classB;
@interface MyNotifiedClass : NSObject
{
classB *_classB;
}
@property (retain, nonatomic, readwrite) classB *classB;
// The implementation file of the class that receives the notification
@implementation MyNotifiedClass
....
@synthesize classB = _classB;
- (void)theMethodThatReceivesTheNotification:(whatever)
{
[_classB doSomethingNowPlease];
}
을 :
// Someplace outside both classes (assuming _classB points to an instance of classB
// and _myNotifiedClass points to an instance of MyNotifiedClass)
[_myNotifiedClass setClassB:_classB];
클래스의 인스턴스 메서드를 인스턴스화하지 않고 호출하는 방법은 없습니다. 당신의 해결책은 클래스 메소드를 호출하거나 classB
이 싱글 톤 이니셜 라이저를 가질 수 있습니다.
Object Livecycles에 대해 명확한 지 모르겠습니다. ClassB가 sigleton 클래스이면 단순히 접근 자로 사용하십시오. ClassB의 어떤 객체라도 존재한다면 ClassB의 Method를 호출하기를 원한다면 ClassNotification 메카니즘을 사용하여 ClassB를 생성하고 dealloc을 파괴한다. 이 짧은 줄이기 : ClassB의 livecycle 귀하의 질문에 대답하는 중요한 부분입니다;) – monkeydom