//// MobileDeviceAccessIPhone.m// Apps@HomeII//// Created by Jeff Laing on 7/11/09.// Copyright 2009 Tristero Computer Systems. All rights reserved.//#import "MobileDeviceAccessIPhone.h"staticid_notificationHandlers=nil;// we create an instance of these so that we can dispatch notifications// to different objects.@interface_handler : NSObject{NSObject*_target;SEL_selector;NSMutableDictionary*_dict;NSString*_notification;}@end@implementation_handlerstaticvoidnotificationDispatcher(CFNotificationCenterRefcenter,void*observer,CFStringRefname,constvoid*alwaysZero1,CFDictionaryRefalwaysZero2){NSMutableDictionary*_notificationHandlers=(NSMutableDictionary*)observer;if(_notificationHandlers){_handler*h=[_notificationHandlersobjectForKey:(NSString*)name];if(h){// NSLog(@"send %@ to %@",NSStringFromSelector(h->_selector),h->_target);[h->_targetperformSelector:h->_selector];}}}-(id)initWithTarget:(NSObject*)targetandSelector:(SEL)selectorandNotification:(NSString*)notificationinDict:(NSMutableDictionary*)dict{if(self=[superinit]){_target=target;_selector=selector;_notification=[notificationcopy];_dict=dict;[_dictsetObject:selfforKey:_notification];CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),_dict,notificationDispatcher,(CFStringRef)_notification,// eg, @"com.myapp.notification"NULL,0);}returnself;}-(void)dealloc{CFNotificationCenterRemoveObserver(CFNotificationCenterGetDarwinNotifyCenter(),_dict,(CFStringRef)_notification,// eg, @"com.myapp.notification"NULL);[_notificationrelease];[superdealloc];}@end@implementationAMNotificationCenter+(void)initialize{_notificationHandlers=[NSMutableDictionarynew];}+(void)send:(SEL)messageto:(id)recieverfor:(NSString*)notification{_handler*h=[[_handleralloc]initWithTarget:recieverandSelector:messageandNotification:notificationinDict:_notificationHandlers];// we can release now, the handler is retained by the dictionary[hrelease];}+(void)ignore:(NSString*)notification{_handler*h=[_notificationHandlersobjectForKey:notification];if(h){// removing it from the dictionary will release it, which// will un-register the observer[_notificationHandlersremoveObject:h];}}/// Send a notification+(void)postNotification:(NSString*)notification{CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(),(CFStringRef)notification,nil,nil,YES);}@end@implementationMobileInstallationProxy// defined in PrivateFrameworks/MobileInstallation.Framework, though not with these argumentsintMobileInstallationBrowse(NSDictionary*options,int(*mibcallback)(NSDictionary*dict,idusercon),idusercon);staticintbrowse_mibcallback(NSDictionary*dict,idresult){NSArray*currentlist=[dictobjectForKey:@"CurrentList"];if(currentlist){for(NSDictionary*appinfoincurrentlist){[(NSMutableArray*)resultaddObject:[[appinfocopy]autorelease]];}}return0;}+(id)browse:(NSString*)kind{if(!kind)kind=@"Any";NSMutableArray*result=[NSMutableArraynew];MobileInstallationBrowse([NSDictionarydictionaryWithObject:kindforKey:@"ApplicationType"],&browse_mibcallback,result);return[resultautorelease];}staticidfoundEntry;staticintlookup_mibcallback(NSDictionary*dict,idsoughtEntry){NSArray*currentlist=[dictobjectForKey:@"CurrentList"];if(currentlist){for(NSDictionary*appinfoincurrentlist){if([[appinfoobjectForKey:@"CFBundleIdentifier"]isEqual:soughtEntry]){foundEntry=[appinfocopy];return;}}}return0;}+(id)lookup:(NSString*)identifier{NSMutableArray*result=[NSMutableArraynew];foundEntry=nil;MobileInstallationBrowse([NSDictionarydictionaryWithObject:@"Any"forKey:@"ApplicationType"],&lookup_mibcallback,identifier);return[foundEntryautorelease];}@end