读取在线托管的 .plist 文件
Reading a .plist file that's hosted online
我正在开发一个需要每两个月更新一次 .plist 文件的应用程序,我不想为此每次都重新提交该应用程序,所以他们是托管 .plist 文件的一种方式在线并让应用程序调用它进行更新?我尝试使用 NSURLConnection (或者我没有正确设置它)但是那没有用......还有其他想法吗?这是我正在使用的示例文件 http://www.iphonedevcentral.com/wp-content/uploads/2009/07/TestData.plist
一如既往地提前致谢,这是我的代码:
NSDictionary *mainDictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"NewsSources" ofType:@"plist"]];
我如何更改代码才能访问在线托管的文件?
您的地址示例中的 .plist 是顶层的 NSArray
,而不是 NSDictionary
。如果您尝试使用它,如果您想要 NSDictionary
.
,您将失败
其内容清晰可见:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array> <================= *** HERE ***
<dict>
<key>title</key>
<string>Batman Begins</string>
<key>coverImage</key>
<string>batman_begins.png</string>
<key>featureLength</key>
<integer>140</integer>
<key>releaseDate</key>
<date>2008-07-08T23:32:07Z</date>
</dict>
<dict>
<key>title</key>
<string>The Dark Knight</string>
<key>coverImage</key>
<string>dark_knight.png</string>
<key>featureLength</key>
<integer>152</integer>
<key>releaseDate</key>
<date>2008-12-10T00:32:07Z</date>
</dict>
<dict>
<key>title</key>
<string>The Prestige</string>
<key>coverImage</key>
<string>prestige.png</string>
<key>featureLength</key>
<integer>130</integer>
<key>releaseDate</key>
<date>2007-02-21T00:32:07Z</date>
</dict>
</array>
</plist>
您可以使用:
NSArray *array = [NSArray arrayWithContentsOfURL:[NSURL URLWithString:@"http://www.iphonedevcentral.com/wp-content/uploads/2009/07/TestData.plist"]];
如果 plist(你想使用)确实是顶层的 NSDictionary
,你可以使用类似的方法:
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:@"linkToNSDictionaryTopLevel.plist"]];
我正在开发一个需要每两个月更新一次 .plist 文件的应用程序,我不想为此每次都重新提交该应用程序,所以他们是托管 .plist 文件的一种方式在线并让应用程序调用它进行更新?我尝试使用 NSURLConnection (或者我没有正确设置它)但是那没有用......还有其他想法吗?这是我正在使用的示例文件 http://www.iphonedevcentral.com/wp-content/uploads/2009/07/TestData.plist 一如既往地提前致谢,这是我的代码:
NSDictionary *mainDictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"NewsSources" ofType:@"plist"]];
我如何更改代码才能访问在线托管的文件?
您的地址示例中的 .plist 是顶层的 NSArray
,而不是 NSDictionary
。如果您尝试使用它,如果您想要 NSDictionary
.
其内容清晰可见:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array> <================= *** HERE ***
<dict>
<key>title</key>
<string>Batman Begins</string>
<key>coverImage</key>
<string>batman_begins.png</string>
<key>featureLength</key>
<integer>140</integer>
<key>releaseDate</key>
<date>2008-07-08T23:32:07Z</date>
</dict>
<dict>
<key>title</key>
<string>The Dark Knight</string>
<key>coverImage</key>
<string>dark_knight.png</string>
<key>featureLength</key>
<integer>152</integer>
<key>releaseDate</key>
<date>2008-12-10T00:32:07Z</date>
</dict>
<dict>
<key>title</key>
<string>The Prestige</string>
<key>coverImage</key>
<string>prestige.png</string>
<key>featureLength</key>
<integer>130</integer>
<key>releaseDate</key>
<date>2007-02-21T00:32:07Z</date>
</dict>
</array>
</plist>
您可以使用:
NSArray *array = [NSArray arrayWithContentsOfURL:[NSURL URLWithString:@"http://www.iphonedevcentral.com/wp-content/uploads/2009/07/TestData.plist"]];
如果 plist(你想使用)确实是顶层的 NSDictionary
,你可以使用类似的方法:
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:@"linkToNSDictionaryTopLevel.plist"]];