【问题标题】:Access instance variable of dumped headers (iOS)访问转储标头的实例变量(iOS)
【发布时间】:2013-08-08 11:06:41
【问题描述】:

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


    【解决方案1】:

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

    【讨论】:

    • 谢谢。方法 object_getInstanceVariable 有效:-(void)noteApplicationFinishedLaunching:(id)launching{ NSString *str; object_getInstanceVariable(self, "_lastNotificationReceivedBundleIdentifier", (void **)&amp;str); NSLog(@"identifier=%@",str); %orig; }
    • 耶!您可以将我的答案标记为正确,以便将来如果有人在搜索相同的问题,他会知道在哪里查看。
    【解决方案2】:

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

    [self valueForKey:@"lastNotificationReceivedBundleIdentifier"];
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-18
      • 1970-01-01
      • 2011-02-21
      • 2023-03-15
      相关资源
      最近更新 更多