I am using Xcode 5. I am working with push notifications in iOS. I am getting satisfying results for background mode and foreground mode that can be debugged easily on an iOS device.
But problem is when app is in closed state and launched by push notification tap but I don't know how to debug in this situation. I know the solution for Xcode 4 but not for Xcode 5.
So is there any solution for Xcode 5 and debugging the app when launching it by push notifications?
Provide steps to debug in this situation.
Edit your project scheme and set "Launch" to "Wait for *.app to be launched manually".
Then Run the project or hit "cmd+R". The app will not be launched automatically, but the debugger will attach to the process as soon as the app launches. So send your test push notification, and launch the app from the push.
Here you go!
it takes few seconds:
1- go to edit schema
2- select run section from left list
3- then in info tab goto part launch options
4- select option: wait for executable to be launched
5- then close the window
6- run the app : the app will build but not launched because it's waiting for you to launch the app manually
7- at this time send your notification to your device
8- tap on the notification and your app will launched and the debugger goes to breakpoints you attached in lines of code
You can also connect to the app in debug mode using the debug menu of Xcode : Debug > Attach to process by PID or name (start typing the name of your target and Xcode will autocomplete for you)
As soon as the app is launched or if it is already launched, the debugger will be plugged. Really helpful in two cases :
notification/location debug
you didn't launch the app through Xcode but you have a strange bug you want to understand
Related
I want to get main app, today-extension debug info at same time.
I run the scheme main app and got only main app debug info.
I try the attach by Process Identifier(today-extension id) but it's blank when I select today-extension process.
What should I do?
Basically select the Watch App as the scheme in xcode, hit build+run
which will build the iOS app and WatchKit app, install the WatchKit
app on to the Watch and attach the debugger to the WatchKit Extension.
Then in xcode select the iOS app in the scheme selector and select the
iPhone as the target device, launch the iOS app by tapping the app
icon on the phone and in xcode in the menu bar select "Debug > Attach
to Process" and select your app in the list. This should result in
having xcode attached to both processes at the same time. If you want
to debug something early in the iOS app's lifecycle you can select
"Debug > Attach to Process by PID or Name..." and type in the process
name of the iOS app prior to launching it manually. This way the
debugger will be attached right when the app launches.
From Apple Developer site.
Note that they discuss WatchKit but it´s the same for Today Extension.
I'm currently trying to handle different application states (closed, background or in a different tab of the app) however when I try to test how the app works when it is closed and receives a push notification(double click home and force close the app then reopen it) I'm not sure where I'm going wrong in the code. Since I'm reopening the app from the phone itself and not xcode I can't test to see which method isn't being reached because no output is available in the console. Is there any way to test a situation like this or simulate a force close event in xcode so that when i re run the app on the phone it also launches in xcode?
I appreciate any responses.
Cheers!
If you force close app or stop (from xcode) then it close the connection with xcode. Then if you open it from phone then it will not make connection with xcode. You must run it from xcode. And there is no difference in opening app from phone or running from xcode. App's flow will be same in both case. So what you want to test that which methods get calls and in which sequence that you can check by rerunning the project.
Update:
Select the Scheme on the toolbar (just left beside from your device or simulator list)
Choose Edit Scheme
Select Run in the left panel
For the Launch option, select Wait for executable to be launched
Refer this link for more details
Since I'm reopening the app from the phone itself and not xcode I can't test to see which method isn't being reached because no output is available in the console.
In Xcode, hold down the Option key and choose Product->Run..., and then edit the Run scheme to use the "Wait for executable to be launched" option. You should then be able to choose Run in Xcode, and then open your app by some other means, such as responding to a notification, and Xcode will still connect and let you debug.
To debug the process after restarting the app again, attach the Xcode debug console to the running process.
In Xcode do:
Debug > Attach to process > [select your process]
I am developing an application for iOS in Objective C with Xcode. This application schedules local push notifications every 6 hours and it is crashing when I open the push notifications.
I need to debug the error to solve it. I can have the mobile connected to Xcode, but as the app is executed from local push notification I can't see the error messages on my Xcode debug console, as I haven't launched my app from Xcode.
Is there a way to have the iOS device connected to my Mac and see what error is happening?
I know that I can go to the mobile settings to view logs, but these logs are too ambigous for me aren't giving any error.
In addition to opening the console log as described by #saurabhgoyal you can tell Xcode to wait for your app to launch and then attach the debugger to it when it does.
Select the scheme you're using to build your app, select edit scheme, and click on the run icon. Then Look for a pair of radio buttons titled "Launch" and select the one with the name "Wait for executable to be launched."
Then when you run your app in Xcode it builds it and installs it on the device but does not launch it.
When your notification fires and the app launches the debugger attaches to your app and you can debug as normal (except that NSLog statements don't print to the debug console any more - an annoyance.)
Yes there is a way to see device logs on Mac.
Connect your iOS device to the Mac system using USB
Launch Xcode–>Window–>Devices
Select your device from the left panel
Now you can see the logs on the screen including the background activities.
In order to save the running logs.
Reproduce the issue or start working on your device on a the app you wanted to capture the logs. After the issue is reproduced click on the Save Console icon bottom right corner Xcode screen
For more details please visit this link
Hope this Helps!
Check your crash log
1.Launch Xcode on your desktop machine.
2.Open the Xcode Devices window. (Window menu -> Devices and Simulators, or Cmd-Shift-2.)
3.Find your device in the left sidebar, then select “device logs”.
Choose a Chrome crash (or multiple crashes) and select “Export” at the bottom of the Organizer window.
my configuration: Apple Watch (WatchOS 2.0.1), iPhone 5S (iOS 9.1) Xcode 7.1 on MacOS X El Capitan.
I can run my app on the iPhone just fine. However, when I try to run my app on the Apple Watch, it seems like it's not possible. What I see in the status bar is the usual steps
Building MyApp on Apple Watch
Installing to Apple Watch
Running MyApp on Apple Watch
And then, in less that a second, it shows
Finished Running MyApp on Apple Watch
As if I had just pressed the stop button in Xcode (but without my having pressed it at all). No error message or warning. It just stops.
As a result, I'm not able to debug my app on the Apple Watch to see the log messages, memory usage, etc.
Any ideas? Thanks in advance for your help!
When this happened to me, I fixed the issue by:
Making sure there are no problems with your Main.storyboard and it has an initial view controller.
Deleted app on phone
Rebooted phone
Rebooted watch
Quit xcode and rebooted mac
You could build the app to iPhone first, wait the watch app sync to watch. (Or you could sync it in companion by turn off and turn on the install switch manually)
Then keep the app running on watch, select Xcode->Debug->Attach to Process->XXXXX Extension(the name of your watch extension)
After a while you should be able to debug the watch app.
After restarting all my devices twice to no avail, here are some tips that sometimes solve the issue. (This whole thing is a headache.) I usually use the combination of these 3 things and it works 90% of the time.
Build for a simulator and then switch back to a real device again.
Switch the Info/Launch scheme setting to "Wait for the executable to be launched", run the project and then switch back to "Automatically".
Delete the Derived Data folder located under ~/Library/Developer/Xcode/DerivedData.
This drove me up the wall when starting out. I found 2 solutions:
Stop wasting time developing for Apple Watch
Found my XCode was disconnecting from my Apple ID. Went to XCode -> Preferences -> Accounts. And noticed "Your session expired, please log in." I could run to iPhone no problem with this error but on Apple Watch it would get stuck on "Running ... Apple Watch"
I'm building an iOS app for which I have Testflight set up, but now I'm running into an interesting issue where I can't properly launch the app from Xcode anymore since I registered my device to test the app through Testflight.
When I try to launch the app from Xcode, it will build fine and even launch it on my phone. However, there will be no output in the console, and a few seconds later the app will crash on my phone and I get the following error message popup in Xcode:
process launch failed: failed to get the task for process 484
If I delete the app from my phone before trying to launch from Xcode, the same thing will happen and the Testflight orange dot will still show up next to the app name on the home screen.
I have tried to change the app's version and build number, but that had no effect. I have not yet tried to unregister my device to test the app through Testflight because I would like to find a good way that facilitates both.
One way I have found to circumvent this problem is create a different app target and run the app with that which seems to work -- but I'm wondering if there is an actual solution to this problem or a better way to work around it.
Thanks in advance.
Turns out Max was on the right track - if I manually specify a non-distribution provisioning profile it will work properly by overriding the Testflight version of the app (the orange dot disappears). Not sure why "automatic" wasn't doing that for me. Thank you!