gpt4 book ai didi

iphone - 如何从远程推送通知中获取我的应用程序中的notification.alertBody?

转载 作者:行者123 更新时间:2023-12-01 19:08:53 25 4
gpt4 key购买 nike

我刚刚按照本教程Push notification进行操作,并成功为我的iPhone应用程序实现了推送通知。我现在可以获取通知详细信息。但是,我想将通知alertBody放在为通知alertBody提供的标签上。

我在显示本地通知中的通知alertBody时有一个代码。但我知道它与推送通知不同,因为它仅用于本地通知。

在我的AppDelagate.m上

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
NSLog(@"Recieved Notification %@",notif);
NSString *_stringFromNotification = notif.alertBody;
[[NSNotificationCenter defaultCenter] postNotificationName:@"Notification" object:_stringFromNotification];
}

在我的ViewController.m上
- (void)viewDidLoad{

[super viewDidLoad];

[[NSNotificationCenter defaultCenter] addObserverForName:@"Notification" object:nil queue:nil usingBlock:^(NSNotification *note)
NSString *_string = note.object;
//Do something with the string--------
}];

}

它在“本地通知”上完美运行,但对于推送通知,则不起作用。如何实现呢?请需要您的帮助。我需要将通知警报正文放在“标签”或“字符串”处。

最佳答案

first of all register for remote notifications in AppDelegate.m in method,

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Invoke APNS.
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}

And then use following delegate method to recieve remote notification:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"Received =%@",userInfo);////userInfo will contain all the details of notification like alert body.
}

关于iphone - 如何从远程推送通知中获取我的应用程序中的notification.alertBody?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18065867/

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