访问转储标头的实例变量(iOS)

时间:2013-08-08 11:06:41

标签: ios theos

我想知道“_lastNotificationReceivedBundleIdentifier”的值,它是类的实例变量。标头从iOS跳板应用程序转储。

@interface SBRemoteNotificationServer : NSObject <APSConnectionDelegate> {
    NSMutableDictionary* _bundleIdentifiersToClients;
    NSMutableDictionary* _environmentsToConnections;
    unsigned _lastPlayedAlertSound;
    NSString* _lastNotificationReceivedBundleIdentifier;
}

但以下代码不起作用:

%hook SBRemoteNotificationServer
-(void)noteApplicationFinishedLaunching:(id)launching{
    NSLog(@"identifier=%@",_lastNotificationReceivedBundleIdentifier);
    %orig;
}
%end

,编译错误是:

error: ‘_lastNotificationReceivedBundleIdentifier’ was not declared in this scope

如何访问和记录此NSString?

2 个答案:

答案 0 :(得分:2)

您可以使用objective-c运行时功能并查看方法object_getInstanceVariable(the_object, "_lastNotificationReceivedBundleIdentifier", (void**)&yourPointer);

答案 1 :(得分:0)

另一个可以尝试的解决方案是:

[self valueForKey:@"lastNotificationReceivedBundleIdentifier"];

其中self是父对象,lastNotificationReceivedBundleIdentifier是变量名。例如与self.lastNotificationReceivedBundleIdentifier相同。