简体   繁体   English

通过推送通知启动时调试应用程序

[英]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方案,粘贴板和推送通知。

  1. In Xcode look in the Source bar, and below Targets there will be Executables. 在Xcode中查看源栏,在目标下面会有可执行文件。
  2. Bring up the inspector for your app in executables. 在可执行文件中为您的应用程序启动检查器。
  3. Click on the Debugging tab tab in the inspector. 单击检查器中的“调试”选项卡选项卡。
  4. Uncheck "Start executable after starting debugger" 取消选中“启动调试器后启动可执行文件”
  5. Check the "Wait for next launch/push notification" 检查“等待下次启动/推送通知”

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,你必须:

  1. Edit your active scheme via "Schemes" dropdown. 通过“方案”下拉列表编辑您的活动方案。 ( + < ) + <
  2. Than choose your product - 'Run MyApp.app' on the left. 比选择你的产品 - 左边的'Run MyApp.app'。
  3. Select 'Info' tab on the right. 选择右侧的“信息”标签。
  4. And finally choose "Wait for MyApp.app to launch" option. 最后选择“等待MyApp.app启动”选项。

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:

  1. Select the Scheme on the toolbar (just left of the device you're debugging with) 在工具栏上选择Scheme (在您正在调试的设备的左侧)
  2. Choose Edit Scheme 选择编辑方案
  3. Select Run in the left panel 在左侧面板中选择“运行”
  4. For the Launch option, select Wait for executable to be launched 对于“ 启动”选项,选择“ 等待 启动 可执行文件”
  5. Close the Scheme Editor and Run your XCode project 关闭Scheme Editor并运行您的XCode项目

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中:

  1. connect iPhone to Macbook with USB 用USB连接iPhone到Macbook
  2. launch the app on the iPhone by tapping the icon 通过点击图标在iPhone上启动应用程序
  3. In Xcode menu, 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,您可以执行以下操作:

  1. Select Scheme option.选择方案选项。

  2. Choose Edit Scheme.选择编辑方案。

  3. Select Run option from the left panel从左侧面板中选择运行选项

  4. In the launch part, select wait for executable to be launched , then close the dialog.在启动部分,选择wait for executable to belaunch ,然后关闭对话框。

  5. 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.

相关问题 推送通知仅在使用 Xcode 启动应用程序时有效 - Push notification works only when app launched with Xcode 应用未启动时如何调试推送通知? - How to debug push notification while app is not launched? 检测应用程序是否从推送通知启动/打开 - Detect if the app was launched/opened from a push notification 通过单击应用程序图标直接启动应用程序时,无法获取通知数据 - Push notification data not getting when app launched directly by clicking app icon 检测应用程序是否通过单击应用程序图标或推送通知启动(当应用程序被用户强制终止时) - Detect if Application is launched by clicking app icon or by push notification (when app is force killed by user) iOS Swift:从推送通知启动应用程序时推送两个视图控制器 - iOS Swift: Pushing two view controllers when app launched from push notification 如果未通过单击“查看”按钮启动应用程序,则检索最新的“推送通知” - Retrieving latest Push Notification if app was not launched by hitting the 'View' button 应用程序尚未启动时的Apple推送通知委托方法 - Apple push notification delegate method when the application is not launched yet 从推送通知启动时,启动viewController中的所有对象 - Initiating all objects in viewController when launched from a push notification 应用程序终止时推送通知 - Push notification when app is terminated
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM