gpt4 book ai didi

iphone - 应用程序运行时推送通知不起作用(事件)

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:22:45 25 4
gpt4 key购买 nike

<分区>

我正在开发一个带有推送通知的简单应用程序,并且我成功地实现了它。当我退出应用程序时,我收到推送通知(效果很好)但是当我打开应用程序并尝试从我的服务器(Web 应用程序)发送消息时,它不会显示任何弹出消息或通知。我错过了什么吗?这是我在 AppDelegate.m 上的代码片段

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

// Let the device know we want to receive push notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
return YES;
}


(void)application:(UIApplication*)application didReceiveRemoteNotification: (NSDictionary*)userInfo{
NSLog(@"Received notification: %@", userInfo);
NSString *messageAlert = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];
NSLog(@"Received Push Badge: %@", messageAlert );
[[NSNotificationCenter defaultCenter] postNotificationName:@"Notification" object:messageAlert];

}

请帮我解决这个问题。谢谢。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com