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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1239000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 16:14:59  来源:igfitidea点击:

Debugging App When Launched by Push Notification

iosiphonepush-notification

提问by Dutchie432

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.

我目前正在开发一个接收推送通知的应用程序。我让这一切都通过 PHP 页面 100% 工作。我的应用程序可以接收多种不同类型的推送通知。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. 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 工作正常 - 但是,当我的推送通知触发此 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.

您对我的任何建议将不胜感激。

回答by Louis Gerbarg

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.

在 XCode < 4.0(对于 XCode >= 4,请参阅下面 delirus 的回答)中,您现在可以配置 Xcode 以在启动应用程序后将调试器附加到应用程序,而不是通过调试器启动应用程序。这使您可以调试根据应用程序的启动状态而变化的内容,例如 URL 方案、粘贴板和推送通知。

  1. In Xcode look in the Source bar, and below Targets there will be Executables.
  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"
  1. 在 Xcode 中查看 Source 栏中,在 Targets 下方将有 Executables。
  2. 在可执行文件中为您的应用程序打开检查器。
  3. 单击检查器中的“调试”选项卡。
  4. 取消选中“启动调试器后启动可执行文件”
  5. 勾选“等待下一次启动/推送通知”

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 单击调试而不是启动应用程序时,将显示一个窗口,告诉它正在等待应用程序启动。然后您在手机上正常启动应用程序,Xcode 将附加到它

回答by matm

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.
  3. Select 'Info' tab on the right.
  4. And finally choose "Wait for MyApp.app to launch" option.
  1. 通过“方案”下拉菜单编辑您的活动方案。( ?+ <)
  2. 然后选择您的产品 - 左侧的“运行 MyApp.app”。
  3. 选择右侧的“信息”选项卡。
  4. 最后选择“等待 MyApp.app 启动”选项。

More herein "Customize Executables in the Scheme Editor" section.

更多信息请参见“在方案编辑器中自定义可执行文件”部分。

EDIT:
In case you miss logs in GDB, see Louis Gerbarg's commentto his answer.

编辑:
如果您错过了 GDB 中的日志,请参阅 Louis Gerbarg对他的回答的评论

回答by bgolson

For XCode 10, 9, 8, 7 & 6:

对于 XCode 10、9、8、7 和 6:

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

Now you can debug when launching from a notification, custom url or by touching the app icon.

现在,您可以在从通知、自定义 URL 或触摸应用程序图标启动时进行调试。

回答by Ali Saeed

In Xcode 6:

在 Xcode 6 中:

  1. connect iPhone to Macbook with USB
  2. launch the app on the iPhone by tapping the icon
  3. In Xcode menu, Debug> Attach to Process> Pick your App
  1. 使用 USB 将 iPhone 连接到 Macbook
  2. 通过点击图标在 iPhone 上启动应用程序
  3. 在 Xcode 菜单中,Debug> Attach to Process> Pick your App

回答by drvdijk

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.

我不使用推送通知,所以我不知道推送通知的确切工作方式。但是,如果可能的话,我会尝试通过让程序的主方法假装已发布通知来模拟推送通知的接收,或者从 applicationDidFinishLaunching: 方法中调用 application:didFinishLaunchingWithOptions: UIApplicationDelegate 方法。

HTH - Cheers, Daan

HTH - 干杯,大安

回答by Ramy Rizkalla

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.

  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.

  1. 选择方案选项。
  2. 选择编辑方案。

  3. 从左侧面板中选择运行选项

  4. 在启动部分,选择wait for executable to belaunch,然后关闭对话框。

  5. 构建并运行项目。您现在可以通过点击应用程序图标或点击通知消息来启动应用程序。