开发者

Delegate is logging non-public events through my app: can those events be detected?

These notices are being logged on behalf of my app (which implements GKSessionDelegate), and I could really make use of these events to help users with connection difficulties. Is there any way I can detect them? There aren't any public instance methods for the delegate that directly refer to these events.

I'm hoping there's some sort of generic event catch-all for delegates that I could rig up.

GKSessionTester[79766:307] BTM: attaching to BTServer
GKSessionTester[79766:307] <<< Session >>> +[GKBluetoothSupport _determineBluetoothStatus]: BT not available - try again later.
GKSessionTester[79766:307] BTM: posting no开发者_如何学JAVAtification BluetoothAvailabilityChangedNotification


As Gonzalo mentions in the comments, it looks like a notification is being posted with the name BluetoothAvailabilityChangedNotification.

Cocoa's notifications system is based around NSNotificationCenter, which maintains a list of observers and forwards notifications based on names, which are simply NSStrings. It is very likely that you can receive notifications if you call:

[[NSNotificationCenter defaultCenter]
    addObserver:self
    selector:@selector(bluetoothAvailabilityChanged:)
    name:@"BluetoothAvailabilityChangedNotification"
    object:nil];

And implement the method:

- (void)bluetoothAvailabilityChanged:(NSNotification *)notification
{
    // maybe [notification userInfo] has some useful info...
}

You might not receive any notifications if GameKit is using a separate notification center object.

Does this count as private API? I would say it's no worse than parsing your console output. You are not calling methods on undocumented classes, you are passively observing notifications posted with a given name.

Of course, Apple's opinion is the only one that matters. If I were in your shoes, I would make sure that:

  1. your app functions correctly if the notification is never posted (because a future iOS might not post it, or you might have to remove the code and resubmit without it);
  2. your app makes no assumptions about the NSNotification's object or contents of its userInfo dictionary (because whatever they contain today might change in the future).

Alternatively, you could figure out a way to intercept your own app's STDOUT and STDERR (any solution that works on generic UNIX may work on iOS) and watch the text for relevant log messages.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜