programing

NSLog로 iOS 8 확장을 디버깅하는 방법은 무엇입니까?

nasanasas 2020. 9. 11. 08:08
반응형

NSLog로 iOS 8 확장을 디버깅하는 방법은 무엇입니까?


- (void)viewDidLoad
{
    NSLog(@"%s", __func__);
    // ...
}

에서 viewDidLoad아이폰 OS 8의 확장 . NSLog엑스 코드에 아무것도 출력한다. NSLog하지만 컨테이너 앱에서는 평소처럼 작동합니다.

확장에서 디버그 메시지의 출력을 얻으려면 어떻게해야합니까?


  1. 디버깅은 앱 확장에 대해 작동합니다.
  2. 시뮬레이터에서도 작동합니다.
  3. 앱 확장이 시뮬레이터에서 충돌하는 경우 앱 확장을 다시 시작하는 것이 쉽지 않을 수 있습니다. 시뮬레이터를 다시 시작하는 것이 빠른 해결책입니다.
  4. 앱 확장을 디버깅하는 단계 :

    1. 컨테이너 앱을 실행합니다. 이 단계에서 Xcode는 컨테이너 앱과 앱 확장을 디바이스 또는 시뮬레이터에 업로드합니다.

    2. 컨테이너 앱을 중지합니다. 이 단계는 시뮬레이터에서 디버그 할 때 중요합니다. 그렇게하지 않으면 Xcode는 시뮬레이터가 사용 중임을 알려줍니다.

    3. Xcode에서 Debug-> Attach to Process-> By Process Identifer (PID) 또는 Name ... 메뉴를 누르고, com.abc.ContainerApp.MyExtension과 같은 앱 확장 식별자를 입력하여 디버깅을 시작합니다. 중단 점을 설정하는 것을 잊지 마십시오. (2014 년 8 월 25 일 업데이트 : MyExtension (확장자 이름)을 직접 입력 할 수 있습니다.)

    4. 기기 또는 시뮬레이터에서 앱 확장을 엽니 다.


2014 년 8 월 23 일 업데이트 :

위의 디버깅 단계가 시뮬레이터의 iOS 8 SDK 베타 5가있는 Xcode 6 베타 6에서 제대로 작동하지 않음을 발견했습니다.

해결책:

  1. 시뮬레이터에서 확장을 실행하십시오.
  2. Xcode 메뉴 디버그-> 프로세스에 연결-> 메뉴의 시스템 섹션에서 "MyExtension (확장자 이름)"을 선택합니다.

중단 점이 작동합니다. 그러나 로그가 출력 창에 표시되지 않는 이유를 모르겠습니다.


나도이 문제가 있습니다. Debug-> Open System Log ... 메뉴에서 시뮬레이터로 이동하면 저에게 효과적입니다.

여기에서 iPhone Simulator의 모든 로그 (확장 프로그램의 로그 포함)를 볼 수 있습니다.

여기에 이미지 설명 입력


NSLog완벽하게 작동 합니다 .

Xcode 디버거가 확장에 연결되어 있지 않기 때문에 Xcode의 디버그 영역에 무엇이 기록되고 있는지 볼 수 없습니다. 확장 프로그램은 포함 된 앱 거의 완전히 독립적입니다. 예를 들어, 별도의 번들 식별자가 있으며 OS에서 별도의 프로세스이기도합니다.

Xcode를 확장에 연결하는 데 다양한 성공을 거두었습니다. 자동으로 연결되는 것 같고 디버그 탐색기에 "Waiting to attach"로 표시되지만 연결되지는 않습니다.

때로는 Xcode에서 확장 대상을 실행할 수 있습니다.

여기에 이미지 설명 입력

그런 다음 내 확장 프로그램을 실행할 응용 프로그램을 선택할 수 있습니다.이 경우에는 알림 센터 인 "오늘"권장 사항을 선택합니다.

여기에 이미지 설명 입력

그리고 때로는 디버거를 내 확장에 연결합니다. 이 방법은 물리적 장치에서만 작동합니다.

첨부되지 않으면 @VinceYaun의 답변에서 수동 첨부 방법을 사용할 수 있습니다.

나는 또한 다른 부착 방법을 사용하여 다양한 성공을 거두었습니다. 대부분은 실패했으며 나중에 수정 될 버그 일뿐입니다.

To view your log messages you go to Window -> Devices in the top bar and select your device. You can bring up the device log from the bottom of that window. If you are testing on a simulator, you can use @BalestraPatrick's answer.

Some of the bugs have been fixed in Beta 2, and my guess is that eventually the debugger will attach automagically when launching the extension.

Update: In the iOS 8 Beta 4 release notes:

Extensions

Fixed in beta 4

  • Extensions sometimes fail to launch when debugging from Xcode.
  • When Extension with UI is killed, it relaunches and is not dismissed.
  • Sometimes your Sharing or Action extension can hang.
  • Redeploying an extension may disable it in Notification Center.

I'm having this problem too. Xcode never attaches my debugger to the extension or displays NSLog messages. If you attach your Xcode debugger manually to your extension process, at least breakpoints work like a charm:

Debug->Attach to process->Your extension name (mine was "com.example.MyExtensionApp.MyExtension")

  1. Create scheme for your extension
  2. Run scheme
  3. In a dialog choose container app
  4. Enjoy

It works for me :)


Xcode 8 is able to debug extensions:

  1. Choose the extension scheme in the combo next to the stop button and run it.
  2. Select the parent application in the dialog that appears.

Result: breakpoints and log work as usual.


What finally allowed me to see the log in the debugging area, based on Michael's suggestion and Apple's documentation, is:

Build & Run the app extension in the simulator and, when prompted for a host app, choose the specific app that you're going to call the extension from. In my case I was launching my Action extension from Safari by pulling up a share sheet on a PDF.

What wasn't working before was following other people's suggestions of using Today as the host but then leaving that app and going over to Safari to call my extension. I no longer even need to run my containing app first before running the extension.

From Apple's Documentation:

In your extension scheme’s Run phase, you specify a host app as the executable. Upon accessing the extension through that specified host’s UI, the Xcode debugger attaches to the extension.


I actually got the logs to run quite simply in Xcode 6.3. Firstly, build and run the containing app. Once the containing app is running on the device, build and run the app extension by changing the scheme to the app extension.

Apple has documentation directly related to debugging, profiling and testing your app extension.


A trick which works for me (although it is quite an ugly one) is to place a dummy UILabel somewhere in the bottom corner of my extension. I usually call it logLabel. It is then possible to update the text of this label with any log statement that you want to get logged. Such approach is not very good if you need to log statements from instances of different classes. And, obviously, it clutters your UI.

However, if you have a fairly simple widget and you don't mind about slight cluttering of the UI this does the trick. I have tried all other solutions outlined in this discussion and, sadly, none of them worked for me.


The only way debugging works for me is by selecting Debug->Attach To Process By PID or Name Then enter the PID not the extension name. You can find the PID by running the extension on a device, go to Window->Devices. Find your device and viewing the console. When you see the name of your extension, its followed by 5 digit number. That is the PID

I also put a bunch of NSLog's in the extension in order to find the PID as well. This is on xCode 7


Encounter the same problem about extension for NSLog, and break points. I have fought it with many days.

Device log can be found as following image. It is at XCode -> Window -> Devices and Simulators.

After enter the Open Console, there is a search field at the top-right of dialog. I can apply filter rule in there. For example, a process name contains Notification key word, or process name must equal to the name of extension target, ex: equal to MyNotificationServiceExtension process name.

장치 로그


Clearly something is broken in Xcode6-B5.

If I try to run a Photo extension on the Simulator I cannot see any Photos.app as an option for the extension attaching process.

시뮬레이터 내의 디버그 옵션

The same, running on a real device, give me the correct behaviour.

실제 장치로 디버그 옵션

In the first case any breakpoint is not honorated. In the latter case, breakpoints work like a charm.


You should know that the container app and extension are totally two difference process in iOS while the LLVM debugs only a thread a time, so when you are debugging, the console never log the extension and never stop at breakpoint.

You can solve most of the problems by @Vince Yuan's method.

However, my problem is that Xcode debugger hardly hook on my keyboard extension on both iOS Simulator and devices, like 1 time in 7-8 runs, It's totally a matter of probability. @Vince Yuan's method also work for just sometimes.

My little experience is that when you run you debug scheme, if the debug Session in the left panel showing that 'No Debug Session', there is no need to open your extension and test it, the debugger didn't hook on, just run again for lucky.

but when you see com.xxx.xxx.xxx is waiting to Attach, the extension can definitely get debugged.

This is a little trick for whom cannot debug iOS extension, especially keyboard extension.


As of Xcode 6 Beta 5, I've been able to use an actual device running iOS8 to debug my extension. Try running it on a device and select Safari to launch into


To overcome all the states caused by ever changing IDE, I'm using iOS Console by lemonjar.com – it displays a console window for any connected iOS device rendering syslog messages regardless the process ID. You can see both app and extension debug log messages at once here.


I could debug my extension with the way I describe below:

  1. Xcode : Debug -> Attach to process by PID or Name. Your extension scheme name.
  2. Then select your main app target and run.

I hope it also works for you guys.

참고 URL : https://stackoverflow.com/questions/24031612/how-to-debug-ios-8-extensions-with-nslog

반응형