简体   繁体   English

用于选择 iTunes 库位置的 API 是什么?

[英]What API is there for selecting iTunes library location?

How does one programatically set the iTunes library location on macOS to custom locations using eg C / Obj-C or Swift API?如何使用 C/Obj-C 或 Swift API 以编程方式将 macOS 上的 iTunes 库位置设置为自定义位置?

Alternatively, environmental settings, such as modifying plists, using the defaults CLI tool, or similar approaches, are also OK for me.或者,环境设置,例如修改 plists、使用defaults CLI 工具或类似方法,对我来说也可以。

Ordinarily, selecting a custom iTunes library location is done by launching iTunes while holding down the option key.通常,通过在按住选项键的同时启动 iTunes 来选择自定义 iTunes 库位置。 I need to be able to do this in eg a unit testing environment / programatically.我需要能够在例如单元测试环境/以编程方式执行此操作。

You may be able to set it via the prefs.您可以通过首选项进行设置。 This is how I access it.这就是我访问它的方式。

-(void)loadITunesPrefLibraryPath {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSDictionary *userPref = [userDefaults persistentDomainForName:@"com.apple.iTunes"];

id dataBaseLoc = [userPref objectForKey:@"Database Location"];
NSLog(@"%s dataBaseLoc is:%@", __PRETTY_FUNCTION__, dataBaseLoc);
NSLog(@"%s dataBaseLoc class is:%@", __PRETTY_FUNCTION__, [dataBaseLoc class]);
NSData* dataBaseData = (NSData*)dataBaseLoc;
BOOL staleBook = NO;
NSError* bookError = nil;
NSURL* dataBaseURL = [NSURL URLByResolvingBookmarkData:dataBaseData options:NSURLBookmarkResolutionWithoutMounting relativeToURL:nil bookmarkDataIsStale:&staleBook error:&bookError];
self.libExtDBfile = dataBaseURL;
}

Once you get the userPrefs for iTunes.一旦你获得了 iTunes 的 userPrefs。 And create a BookMarkData from URL.并从 URL 创建 BookMarkData。 You might be able to set it via你可以通过设置它

[userPref setObject:newDataBaseLoc forKey:@"Database Location"];

also see next answer for possible ITLibrary framework private API access另请参阅可能的 ITLibrary 框架私有 API 访问的下一个答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM