一 程序未启动
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//...
NSDictionary* remoteNotification = [launchOptions objectForKey:
UIApplicationLaunchOptionsRemoteNotificationKey];
BOOL lanuchFromNotification = remoteNotification != nil;
if (lanuchFromNotification) {
//增加点击通知的处理
}
//...
return YES;
}
二 程序已启动但是处于后台
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
{
//增加点击通知的处理
}
三 程序处于前台
项目中用到的是个推推送,个推提供了一个方法可以在程序运行的时候捕捉到通知
- (void)GeTuiSdkDidReceivePayloadData:(NSData *)payloadData andTaskId:(NSString *)taskId andMsgId:(NSString *)msgId andOffLine:(BOOL)offLine fromGtAppId:(NSString *)appId
{
if (!offLine) {
//程序处于前台接收到推送
}
}
四 相关技巧
1 删除通知栏某个APP的所有通知
//需要#import <UserNotifications/UserNotifications.h>
[[UNUserNotificationCenter currentNotificationCenter]removeAllDeliveredNotifications];
网友评论