(1) . 应用开启时 , 应用在前台
(2) . 应用开启时 , 应用在后台
(3) . 应用未启动(应用被杀死)
1 . 如果应用处于 (1) 状态 , 则不会发出声音 , 会直接调用appDelegate的代理方法didReceiveRemoteNotification
,此时如果想收到类似系统的弹窗提示,则需要自定义弹窗,提示音,振动(弹窗可以参考 : ForeNotification)
AudioServicesPlaySystemSound(1007);//系统提示音
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);//震动
2 . 如果应用处于 (2) 状态 , 则会发出提示音, 点击推送消息 , 则会调用appDelegate的代理方法didReceiveRemoteNotification
3 . 如果应用处于 (3) 状态,则会发出提示音 , 点击推送消息 , 则会开启应用 , 在下面这个方法中会带上launchOptions这个参数,如果实现了application:didReceiveRemoteNotification:fetchCompletionHandler:
这个方法,则会调用这个方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSDictionary *remoteNotification = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
if (remoteNotification) {
//自定义的BOOL值,用来标记是从通知启动的应用
self.isLaunchedByNotification = YES;
}else{
}
[self checkIsLaunchedByNotification];
return YES;
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSDictionary *aps = [userInfo valueForKey:@"aps"];
NSDictionary *alert = [aps valueForKey:@"alert"];
NSString * body = alert[@"body"];
if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
//处于前台时
[EBForeNotification handleRemoteNotification:@{@"aps":@{@"alert":[NSString stringWithFormat:@"%@",body]}} soundID:1312];
}else{
//处于后台时
[self gotoMessageVC];
}
}
#pragma mark - 检测是否从通知栏启动得应用
- (void)checkIsLaunchedByNotification{
if (self.isLaunchedByNotification) {
[self gotoMessageVC];
}
}
#pragma mark - 点击了通知菜单(当应用在前台时,收到推送,点击了自定义的弹窗,调用的方法)
- (void)clickBannerView:(NSNotification *)notification{
NSDictionary * dict = notification.object;
[self gotoMessageVC];
}
#pragma mark - 跳转到消息界面(点击通知菜单/点击通知栏启动应用时)
- (void)gotoMessageVC{
if([self.window.rootViewController isEqual:self.tabBarController]){
if([self.tabBarController.selectedViewController isKindOfClass:[UINavigationController class]]){
UINavigationController * nav = self.tabBarController.selectedViewController;
if (![nav.topViewController isKindOfClass:[MessagesViewController class]]) {
MessagesViewController *messageVC = [[MessagesViewController alloc] init];
messageVC.hidesBottomBarWhenPushed = YES;
[nav.visibleViewController.navigationController pushViewController:messageVC animated:YES];
}
}
}
}
1.应用在前台/后台 (应用被杀死就收不到了)
2.应用实现了application:didReceiveRemoteNotification:fetchCompletionHandler:
3.如果仅仅实现了application:didReceiveRemoteNotification:
,没有实现application:didReceiveRemoteNotification:fetchCompletionHandler:
,应用只有在前台时才能收到静默推送 , 应用在后台时,收不到静默推送
介绍: 极光推送提供了自定义消息推送 , 这种推送只有当应用在 前台 时才能收到 ; 当应用在 后台/被杀死 时,这时候的自定义消息被保存下来,直到应用处于前台时,应用才会收到.
使用场景: 当需要在前台处理大量数据的时候,可以使用自定义消息,例如应用某个模块需要更新了,这时候后台发送个自定义消息,等到应用启动了就可以自动去下载
// 使用自定义消息,需要在通知中心注册
// 注册通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveJPushCustomMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil];
// 接收到JPush的自定义消息推送
- (void)receiveJPushCustomMessage:(NSNotification *)notification {
NSDictionary *userInfo = [notification userInfo];
NSString *title = [userInfo valueForKey:@"title"];
NSString *content = [userInfo valueForKey:@"content"];
NSDictionary *extra = [userInfo valueForKey:@"extras"];
}
总结:
1.应用在后台/前台/被杀死,都可以收到普通的远程推送
2.应用被杀死时,可以通过Background Fetch短时间唤醒应用
3.应用在后台/前台时,可以通过静默推送,修改一些数据
4.自定义消息应用在
本文由 投稿者 创作,文章地址:https://blog.isoyu.com/archives/ios-yuanchengtuisongjingmotuisongzidingyixiaoxituisong.html
采用知识共享署名4.0 国际许可协议进行许可。除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。最后编辑时间为:8月 15, 2018 at 12:18 上午