当应用程序在ios目标c中处于活动状态时如何获得推送通知? [英] How to get push notification when app is in active state in ios objective c?

查看:32
本文介绍了当应用程序在ios目标c中处于活动状态时如何获得推送通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,我在其中实现了苹果推送通知.当我的应用程序处于后台状态时,我可以收到推送通知,但是当我的应用程序处于活动状态时,我无法收到任何推送通知,请问有什么可以帮忙的吗?

I am working on an app in which I have implemented apple push notification. When my app is in background state then I am able to receive push notifications but when my app is in active state then I am not able to get any push notifications, can anypne help on this?

推荐答案

尝试查看didReceiveRemoteNotification

 - (void)application:(UIApplication *)application 
    didReceiveRemoteNotification:(NSDictionary *)userInfo 
    fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler

在所有状态下接收远程通知的委托方法.

delegate method to receive remote notification in all state.

如果您想在活动状态下显示通知警报.使用 HDNotificationView 显示通知警报.

If you want to show the notification alert in active state. use HDNotificationView to show notification alert.

像这样:

if(application.applicationState == UIApplicationStateActive) {

[HDNotificationView showNotificationViewWithImage:[UIImage imageNamed:@"Icon-40.png"]
                                                            title:title
                                                          message:message
                                                       isAutoHide:YES
                                                          onTouch:^{
                                                              /// On touch handle. You can hide notification view or do something
                                                              [HDNotificationView hideNotificationViewOnComplete:nil];
                                                          }];
}

这篇关于当应用程序在ios目标c中处于活动状态时如何获得推送通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆