推送通知有问题。当有人点击通知时,我想调用一些方法。
当应用运行不简单时(application:didFinishLaunchWithOptions call method
)。但是,当应用程序在后台运行时,我必须在点按后调用方法,而不是在收到通知(didReceiveRemoteNotification
)之后调用方法。
我不知道该怎么做。
当应用在后台时,是否有一些方法可以检查通知是否已被点击?
答案 0 :(得分:0)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (launchOptions)
{ //launchOptions is not nil
NSDictionary *userInfo = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
userInfoDic = userInfo;
if (apsInfo)
{ //apsInfo is not nil
[self performSelector:@selector(postNotificationToPresentPushMessagesVC)
withObject:nil
afterDelay:1];
}
}
return YES;
}
-(void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictionary *) userInfo
{
UIApplicationState state = [app applicationState];
if (state == UIApplicationStateBackground)
{
[self postNotificationToPresentPushMessagesVC];
}
else
{
...
}
}
-(void)postNotificationToPresentPushMessagesVC
{
[[NSNotificationCenter defaultCenter]postNotificationName:@"recievePush" object:userInfoDic];
}