这个东西坑了我好几次了
在调用JPush设置别名和标签的方法之前,一定要在登录成功之后。
JPush提供了几种通知的状态
extern NSString *const kJPFNetworkIsConnectingNotification; // 正在连接中
extern NSString *const kJPFNetworkDidSetupNotification; // 建立连接
extern NSString *const kJPFNetworkDidCloseNotification; // 关闭连接
extern NSString *const kJPFNetworkDidRegisterNotification; // 注册成功
extern NSString *const kJPFNetworkDidLoginNotification; // 登录成功
extern NSString *const kJPFNetworkDidReceiveMessageNotification; // 收到消息(非APNS)
extern NSString *const kJPFServiceErrorNotification; // 错误提示
通过通知中心进行监听 就可以了
//JPush 监听登陆成功
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(networkDidLogin:)
name:kJPFNetworkDidLoginNotification
object:nil];
记得要删除
/**
* 登录成功,设置别名,移除监听
*
* @param notification <#notification description#>
*/
- (void)networkDidLogin:(NSNotification *)notification {
NSLog(@"已登录");
[JPUSHService setAlias:@"123456" callbackSelector:nil object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:kJPFNetworkDidLoginNotification
object:nil];
}