[英]Debugging App When Launched by Push Notification
I am currently developing an app that receives Push Notifications.我目前正在开发一个接收推送通知的应用程序。 I have this all working 100% through a PHP page.我让这一切都通过 PHP 页面 100% 工作。 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. PHP 处理这个并将不同的信息包发送到我的应用程序,这些信息包都收到了。
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.我的一种推送类型应该打开一个 UIView,它与几个不同的服务器建立多个连接并来回协商数据。 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.例如,当从主菜单触发时,此 UIView 工作正常 - 但是,当我的推送通知触发此 UIView 出现时,套接字连接未按预期运行。
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.据我所知(我相对较新)当应用程序从推送通知启动时,无法将该执行链接到调试器/控制台/等......我在尝试调试代码时遇到了非常困难的时间UIAlertViews,因为在各个服务器之间有很多来回的通信线路。
Any advice you have for me would be greatly appreciated.您对我的任何建议将不胜感激。
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. 在XCode <4.0(对于XCode> = 4,请参阅下面的delirus答案)中,您现在可以配置Xcode以在启动后将调试器附加到应用程序,而不是通过调试器启动应用程序。 This lets you debug things that vary based on the launch state of your application, such as URL schemes, pasteboards, and push notifications. 这使您可以根据应用程序的启动状态调试不同的内容,例如URL方案,粘贴板和推送通知。
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. 现在,当您从Xcode单击调试而不是启动应用程序时,将显示一个窗口,告知它正在等待应用程序启动。 You then launch the app normally on the phone and Xcode attaches to it 然后,您可以在手机上正常启动应用程序,并将Xcode连接到它
For Xcode 4 you have to: 对于Xcode 4,你必须:
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. 如果您错过了GDB中的日志,请参阅Louis Gerbarg对其答案的评论 。
For XCode 10, 9, 8, 7 & 6: 对于XCode 10,9,8,7和6:
Now you can debug when launching from a notification, custom url or by touching the app icon. 现在,您可以在从通知,自定义URL或触摸应用程序图标启动时进行调试。
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. 但是,我尝试通过让程序的main方法假装在可能的情况下发布通知,或者在applicationDidFinishLaunching:方法中调用应用程序:didFinishLaunchingWithOptions:UIApplicationDelegate方法来模仿接收推送通知。
HTH - Cheers, Daan HTH - 干杯,大安
In Xcode 6: 在Xcode 6中:
Debug
> Attach to Process
> Pick your App 在Xcode菜单中, Debug
> Attach to Process
> Pick your App For Xcode 11 and 10, you can do the following:对于 Xcode 11 和 10,您可以执行以下操作:
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.在启动部分,选择wait for executable to belaunch ,然后关闭对话框。
Build and run the project.构建并运行项目。 You can now launch the app either by tapping the app icon, or by tapping on the notification message.您现在可以通过点击应用程序图标或点击通知消息来启动应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.