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

问题描述 投票:1回答:2

我想知道“_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?

ios theos
2个回答
2
投票

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


0
投票

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

[self valueForKey:@"lastNotificationReceivedBundleIdentifier"];

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

© www.soinside.com 2019 - 2024. All rights reserved.