iOS pop至指定页面

文/oneDemo(简书作者)
原文链接:http://www.jianshu.com/p/e47dafd75aac
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。

for (UIViewController *controller in self.navigationController.viewControllers) {

    if ([controller isKindOfClass:[你要跳转到的Controller class]]) {

        [self.navigationController popToViewController:controller animated:YES];

    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现通过推送打开指定页面,你需要在推送的 payload 中添加一个 `aps` 字段,其中包含一个 `content-available` 属性和一个 `data` 属性。`content-available` 属性告诉系统该推送是一个“静默”推送,不会显示在屏幕上,但会在后台触发一个应用程序回调。`data` 属性可以包含一些自定义数据,比如要打开的页面的标识符。 然后,在你的应用程序中,你需要实现一个继承自 `UNUserNotificationCenterDelegate` 的类,并重写 `userNotificationCenter(_:didReceive:withCompletionHandler:)` 方法。在这个方法中,你可以检查推送的 `userInfo`,并根据其中包含的数据打开指定页面。具体实现可以参考下面的代码示例: ```swift import UserNotifications class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate { func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { let userInfo = response.notification.request.content.userInfo if let page = userInfo["page"] as? String { // 打开指定页面 // ... } completionHandler() } } ``` 同时,你还需要在应用程序启动时注册通知,并设置该类为通知中心的代理。具体实现可以参考下面的代码示例: ```swift let center = UNUserNotificationCenter.current() let delegate = NotificationDelegate() center.delegate = delegate center.requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in // 注册通知成功或失败 // ... } ``` 最后,在你的推送服务端代码中,你需要将要打开的页面的标识符添加到推送的 `data` 字段中,然后将整个 payload 发送到 APNs 服务器。具体实现可以参考下面的代码示例: ```json { "aps": { "content-available": 1 }, "data": { "page": "myPage" } } ``` 其中,`page` 字段的值可以是任何你自定义的字符串,用来表示要打开的页面的标识符。在应用程序中,你可以根据这个标识符来决定打开哪个页面

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值