本文介绍了在哪里可以找到最新的实时汇率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将实时货币汇率链接到我的iPhone应用程序?首先,有人知道我可以获取汇率的任何网站吗?其次,如何将其链接到我的应用程序?我想做这个程序的工作。
How do I link live currency exchange rates to my iPhone app? First, anyone know any sites where I can get the exchange rates? And second, how do I link that to my app? I want to do what this app does. http://the-dream.co.uk/currencee/
推荐答案
这是,但是,如果您使用可以使用以下方法进行。
Here is a blog post about this, however to recap, if you use TBXML you can do it with the methods below.
它们执行以下操作:
- 假设您已将可变字典对象作为名为 exchangeRates 的类属性, li>将欧元设置为基本汇率(值1.0)
- 调用欧洲中央银行的汇率XML提要并对其进行解析。
-
调用loadExchangeRates()方法后,您可以通过以下操作获得特定汇率:
- Assume you have made a mutable dictionary object as a class property called exchangeRates
- Set's EUR as the base rate (value of 1.0)
- Call the European Central Bank's exchange rate XML feed and parses it.
After you've called the loadExchangeRates() method you can obtain a specific exchange rate by doing:
NSDecimalNumber *rate = [NSDecimalNumber decimalNumberWithString:[self.exchangeRates objectForKey:@"USD"]];
以下是方法:
- (void)loadExchangeRates {
// initialize rate array
exchangeRates = [[NSMutableDictionary alloc] init];
// Load and parse the rates.xml file
TBXML * tbxml = [[TBXML tbxmlWithURL:[NSURL URLWithString:@"http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml"]] retain];
// If TBXML found a root node, process element and iterate all children
if (tbxml.rootXMLElement)
[self traverseElement:tbxml.rootXMLElement];
// add EUR to rate table
[exchangeRates setObject:@"1.0" forKey:@"EUR"];
// release resources
[tbxml release]; }
- (void) traverseElement:(TBXMLElement *)element {
do {
// Display the name of the element
//NSLog(@"%@",[TBXML elementName:element]);
// Obtain first attribute from element
TBXMLAttribute * attribute = element->firstAttribute;
// if attribute is valid
NSString *currencyName;
while (attribute) {
/* Display name and value of attribute to the log window
NSLog(@"%@->%@ = %@",
[TBXML elementName:element],
[TBXML attributeName:attribute],
[TBXML attributeValue:attribute]);
*/
// store currency
if ([[TBXML attributeName:attribute] isEqualToString: @"currency"]) {
currencyName = [TBXML attributeValue:attribute];
}else if ([[TBXML attributeName:attribute] isEqualToString: @"rate"]) {
// store currency and rate in dictionary
[exchangeRates setObject:[TBXML attributeValue:attribute] forKey:currencyName];
}
// Obtain the next attribute
attribute = attribute->next;
}
// if the element has child elements, process them
if (element->firstChild)
[self traverseElement:element->firstChild];
// Obtain next sibling element
} while ((element = element->nextSibling));
}
这篇关于在哪里可以找到最新的实时汇率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!