[英]How to call a function when receive push notification?
我正在使用带推送通知的iPhone应用程序。 我的问题是,当我收到推送通知而不创建该classB的实例或使用静态方法时,如何从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];
}
您显然必须在此类中设置classB
的实例,然后才能起作用:
// Someplace outside both classes (assuming _classB points to an instance of classB
// and _myNotifiedClass points to an instance of MyNotifiedClass)
[_myNotifiedClass setClassB:_classB];
如果不实例化类,则无法调用类的实例方法。 您的解决方案是调用类方法,或者classB
可能具有单例初始化程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.