通过推送通知启动应用程序时进行调试
我目前正在开发一个接收推送通知的应用程序。 我通过 PHP 页面使这一切 100% 正常工作。 我的应用程序可以接收多种不同类型的推送通知。 PHP 处理这个问题并向我的应用程序发送不同的信息包,这些信息包都被很好地接收。
但是,当用户“查看”通知并且我的应用程序启动时,我显然想要采取与用户刚刚手动启动应用程序不同的操作 - 最重要的是,根据推送通知类型采取不同的操作。 我已经让这个工作正常......结构上。
我的推送类型之一应该打开一个 UIView,它与多个不同的服务器建立多个连接并来回协商数据。 例如,当从主菜单触发时,此 UIView 工作正常 - 但是,当我的推送通知触发此 UIView 出现时,套接字连接未按预期运行。
现在我的问题不是关于套接字,而是关于 - 如何调试这样的问题? 据我所知(我相对较新),当应用程序从推送通知启动时,无法将该执行链接到调试器/控制台/等...我在尝试使用调试代码时遇到了非常困难的时间UIAlertViews,因为各个服务器之间有许多来回通信线路。
如果您对我有任何建议,我将不胜感激。
I am currently developing an app that receives Push Notifications. I have this all working 100% through a PHP page. There are several different types of push notifications my app can receive. The PHP handles this and sends different packets of information to my app which are all received just fine.
However, when the users "views" the notification and my app launches, I obviously want to take a different action than I would if the user just launched the app manually - and on top of that, different actions depending on the push notification type. I have got this working fine... structurally.
One of my push types is supposed to open a UIView that makes several connections to several different servers and negotiates data back and forth. This UIView works fine when, for example, triggered from the main menu - however when my push notification is triggering this UIView to appear, the socket connections are not acting as expected.
Now my question is not about the sockets, but more so - How do you debug such a problem?? From what I can tell (I am relatively new) when the app launched from a push notification there is no way to link that execution to the debugger / console / etc... I am having a very difficult time trying to debug the code using UIAlertViews, as there are many lines of communication back and forth between the various servers.
Any advice you have for me would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在Xcode中< 4.0(对于 Xcode >= 4,请参阅下面 delirus 的回答),您现在可以配置 Xcode 在启动应用程序后将调试器附加到应用程序,而不是通过调试器启动应用程序。 这使您可以调试根据应用程序的启动状态而变化的内容,例如 URL 方案、粘贴板和推送通知。
现在,当您从 Xcode 单击“调试”而不是启动应用程序时,将显示一个窗口,告诉它正在等待应用程序启动。 然后,您可以在手机上正常启动该应用程序,并且 Xcode 会附加到该应用程序上
In Xcode < 4.0 (for Xcode >= 4, see answer by delirus below), you can now configure Xcode to attach the debugger to the app after you launch it, instead of launching the app through the debugger. This lets you debug things that vary based on the launch state of your application, such as URL schemes, pasteboards, and push notifications.
Now when you click debug from Xcode instead of launching the app a window will display telling it is waiting for the app to launch. You then launch the app normally on the phone and Xcode attaches to it
对于 Xcode 4,您必须:
“方案”下拉菜单。 (⌘+<)
MyApp.app' 在左侧。
MyApp.app to launch”选项。
更多信息此处 在“方案编辑器中自定义可执行文件”部分
编辑:
如果您错过 GDB 中的日志,请参阅 Louis Gerbarg 的 评论 他的回答。
For Xcode 4 you have to:
"Schemes" dropdown. (⌘+<)
MyApp.app' on the left.
MyApp.app to launch" option.
More here in "Customize Executables in the Scheme Editor" section.
EDIT:
In case you miss logs in GDB, see Louis Gerbarg's comment to his answer.
适用于 Xcode 10、9、8、7 和 6:
现在您可以调试从通知、自定义 URL 或触摸应用程序图标启动时。
For Xcode 10, 9, 8, 7 & 6:
Now you can debug when launching from a notification, custom url or by touching the app icon.
我不使用推送通知,所以我不知道推送通知的确切工作原理。 但是,我会尝试通过让程序的主要方法假装已发布通知(如果可能)来模拟接收推送通知,或者从 applicationDidFinishLaunching: 方法中调用 application:didFinishLaunchingWithOptions: UIApplicationDelegate 方法。
HTH - 干杯,达安
I'm not working with push notifications, so I don't know the exact working of push notifications. However, I'd try mimicking the receipt of a push notification by letting the main method of your program pretend a notification was posted if possible, or calling the application:didFinishLaunchingWithOptions: UIApplicationDelegate method from within the applicationDidFinishLaunching: method.
HTH - Cheers, Daan
在 Xcode 6 中:
调试
> >附加到进程
> 选择您的应用程序In Xcode 6:
Debug
>Attach to Process
> Pick your App对于 Xcode 11 和 10,您可以执行以下操作:
选择方案选项。
选择编辑方案。
从左侧面板中选择“运行”选项
在启动部分中,选择等待可执行文件启动,然后关闭对话框。
构建并运行项目。 您现在可以通过点击应用程序图标或点击通知消息来启动应用程序。
For Xcode 11 and 10, you can do the following:
Select Scheme option.
Choose Edit Scheme.
Select Run option from the left panel
In the launch part, select wait for executable to be launched, then close the dialog.
Build and run the project. You can now launch the app either by tapping the app icon, or by tapping on the notification message.