2015-11-14 67 views

回答

19

要做到这一点,你需要为你的应用程序可以与打开每个ViewController一个identifier,然后检查​​在application:didFinishLaunchingWithOptions:launchOptions参数在AppDelegate下面是步骤来这样做:

  1. 在你PFPush,使用setData一键添加到您的有效载荷与标识符:notification.setData(["alert":"your notification string", "identifier":"firstController"])

  2. 设置identifier上的各ViewController通过选择它并改变下列值

Setting the Storyboard ID

  • 让您的推送通知发送故事板ID在其​​与键identifier
    1. 检查应用程序中的ID:didFinishLaunchingWithOptions:在该函数的末尾添加以下内容:
    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 
    } 
    
    +0

    我正在使用PFPush,此刻,我的推送通知只包含一串文字 – mechdon

    +0

    @mechdon在推送通知中使用'setData'方法发送数据以及使用字典'[“identifier”:“ firstController“]'或任何你的标识符应该是 – kabiroberai

    +0

    @mechdon你打算如何指定'ViewController'打开它? – kabiroberai

    2

    在AppDelegate中,你会得到一个委托回调“didFinishLoading”或“didReceivePushNotification”的方法(根据您的应用程序在背景或前景)。在该方法中,获取最顶层的视图控制器的实例,然后创建您想要显示的特定视图控制器,并从最顶层的视图控制器呈现/推送。

    +3

    萨蒂扬,感谢您的回答,这也是正确的。但是我给了kabiroberai的答案,因为他是我的问题最完整的解决方案。 – mechdon

    0
    UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 
        if (notification) 
        { 
         [self application:application didReceiveRemoteNotification:(NSDictionary*)notification]; 
        } 
    
    相关问题