我的应用程序允许向用户发送远程推送通知。当用户点击推送通知时,如何使其在特定的视图控制器中打开?我希望根据接收到的推送通知,应用程序能够打开并导航到特定的视图控制器。请问该如何实现?
ViewController
设置一个标识符
,然后在AppDelegate
中检查application:didFinishLaunchingWithOptions:
的launchOptions
参数中的payload
。以下是实现此操作的步骤:
在您的PFPush
中,使用setData
向负载添加带有标识符的键:notification.setData(["alert":"your notification string", "identifier":"firstController"])
通过选择它并更改以下值,为每个ViewController
设置标识符
payload
中发送故事板ID,并使用键标识符
application:didFinishLaunchingWithOptions:
中的ID:if let payload = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary, identifier = payload["identifier"] as? String {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier(identifier)
window?.rootViewController = vc
}
UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (notification)
{
[self application:application didReceiveRemoteNotification:(NSDictionary*)notification];
}
alert
的键,并将其值设置为你想要发送的警报,就像这样:["alert":"您的通知字符串", "identifier":"firstController"]
。 - kabiroberai