Skip to content

Commit 5607a35

Browse files
committed
Adding 2 methods to XMPPModule: didActivate & didDeactivate. These methods are easier (and simpler) for subclasses to override, compared to the original activate & deactivate methods.
1 parent f27adcc commit 5607a35

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

Core/XMPPModule.m

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ - (void)dealloc
5454

5555
/**
5656
* The activate method is the point at which the module gets plugged into the xmpp stream.
57-
* Subclasses may override this method to perform any custom actions,
58-
* but must invoke [super activate:aXmppStream] at some point within their implementation.
57+
*
58+
* It is recommended that subclasses override didActivate, instead of this method,
59+
* to perform any custom actions upon activation.
5960
**/
6061
- (BOOL)activate:(XMPPStream *)aXmppStream
6162
{
@@ -73,6 +74,8 @@ - (BOOL)activate:(XMPPStream *)aXmppStream
7374

7475
[xmppStream addDelegate:self delegateQueue:moduleQueue];
7576
[xmppStream registerModule:self];
77+
78+
[self didActivate];
7679
}
7780
};
7881

@@ -84,13 +87,28 @@ - (BOOL)activate:(XMPPStream *)aXmppStream
8487
return result;
8588
}
8689

90+
/**
91+
* It is recommended that subclasses override this method (instead of activate:)
92+
* to perform tasks after the module has been activated.
93+
*
94+
* This method is only invoked if the module is successfully activated.
95+
* This method is always invoked on the moduleQueue.
96+
**/
97+
- (void)didActivate
98+
{
99+
// Override me to do custom work after the module is activated
100+
}
101+
87102
/**
88103
* The deactivate method unplugs a module from the xmpp stream.
89104
* When this method returns, no further delegate methods on this module will be dispatched.
90105
* However, there may be delegate methods that have already been dispatched.
91106
* If this is the case, the module will be properly retained until the delegate methods have completed.
92107
* If your custom module requires that delegate methods are not run after the deactivate method has been run,
93108
* then simply check the xmppStream variable in your delegate methods.
109+
*
110+
* It is recommended that subclasses override didDeactivate, instead of this method,
111+
* to perform any custom actions upon deactivation.
94112
**/
95113
- (void)deactivate
96114
{
@@ -102,6 +120,8 @@ - (void)deactivate
102120
[xmppStream unregisterModule:self];
103121

104122
xmppStream = nil;
123+
124+
[self didDeactivate];
105125
}
106126
};
107127

@@ -111,6 +131,18 @@ - (void)deactivate
111131
dispatch_sync(moduleQueue, block);
112132
}
113133

134+
/**
135+
* It is recommended that subclasses override this method (instead of deactivate:)
136+
* to perform tasks after the module has been deactivated.
137+
*
138+
* This method is only invoked if the module is transitioned from activated to deactivated.
139+
* This method is always invoked on the moduleQueue.
140+
**/
141+
- (void)didDeactivate
142+
{
143+
// Override me to do custom work after the module is deactivated
144+
}
145+
114146
- (dispatch_queue_t)moduleQueue
115147
{
116148
return moduleQueue;

0 commit comments

Comments
 (0)