如何在目标 c 中的 didFinishLaunchingWithOption 应用程序方法中检测远程通知? [英] How to detect Remote notification in didFinishLaunchingWithOption application method in objective c?

查看:20
本文介绍了如何在目标 c 中的 didFinishLaunchingWithOption 应用程序方法中检测远程通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当应用程序不在后台模式、非活动模式和应用程序完全关闭时.而不是如何使用应用程序的委托didFinishLaunchingWithOption"方法检测他们的任何通知.我已经搜索了很多关于它但没有得到任何东西.请帮忙.

when app in not in background mode ,inactive mode and app is completely closed. than how to detect is their any notification using application's delegate "didFinishLaunchingWithOption" method. i have searched a lot about it but not get anything. please help .

谢谢

推荐答案

以下方法用于通知

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
 UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
   if (notification)
   {


   }
}


 -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    NSString *token = [[[[deviceToken description]
                      stringByReplacingOccurrencesOfString:@"<"withString:@""]
                     stringByReplacingOccurrencesOfString:@">" withString:@""]
                    stringByReplacingOccurrencesOfString: @" " withString: @""];
    NSLog(@"Token:%@",token);

}

//app is forground this method will access
 -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{

}
//need to on teh background fetch option in info plist
//app is background state this below mthod will call while notification receives
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
 {
  NSLog(@"Background mode working%@",userInfo);

  if([userInfo[@"aps"][@"content-available"] intValue]== 1) //it's the silent notification when recive preferences and text messages
  {
  }
 }

//handling interactive notification
   - (void)application:(UIApplication *)application handleActionWithIdentifier:(nullable NSString *)identifier forLocalNotification:(nonnull UILocalNotification *)notification completionHandler:(nonnull void (^)())completionHandler {
  }

这篇关于如何在目标 c 中的 didFinishLaunchingWithOption 应用程序方法中检测远程通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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