Доступ к переменной экземпляра сброшенных заголовков (iOS)
Я хочу знать значение "_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 ответа
Решение
Вы могли бы, вероятно, использовать возможности времени выполнения targe t-c и взглянуть на метод object_getInstanceVariable(the_object, "_lastNotificationReceivedBundleIdentifier", (void**)&yourPointer);
Еще одно решение:
[self valueForKey:@"lastNotificationReceivedBundleIdentifier"];
где self
является родительским объектом и lastNotificationReceivedBundleIdentifier
это имя переменной. например, такой же, как self.lastNotificationReceivedBundleIdentifier
,