iphone - 我在哪里可以找到更新的实时汇率?

标签 iphone currency

如何将实时货币汇率链接到我的 iPhone 应用程序?首先,谁知道有哪些网站可以查询汇率?其次,如何将其链接到我的应用程序?我想做这个应用程序所做的事情。 http://the-dream.co.uk/currencee/

最佳答案

这是一个blog post关于这一点,但是回顾一下,如果您使用 TBXML您可以通过以下方法来完成。

他们执行以下操作:

  1. 假设您已创建一个可变字典对象作为名为 exchangeRates 的类属性
  2. 将欧元设置为基本汇率(值为 1.0)
  3. 调用欧洲中央银行的汇率 XML Feed 并对其进行解析。
  4. 调用 loadExchangeRates() 方法后,您可以通过以下操作获取特定汇率:

    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));
}

关于iphone - 我在哪里可以找到更新的实时汇率?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1192025/

相关文章:

javascript - appcelerator titan -TableViewRow selectedBackgroundColor 去除圆 Angular

php - 转换输入为 "100K"、 "100M"等的金额

floating-point - 为什么不使用 Double 或 Float 来表示货币?

iphone - 屏幕上 CALayers 的混合模式?那可能吗?

iphone - 为 UItextview 键盘设置动画

iphone - 如何获取 UIButton 的 UIControlTouchDragInside 和 UIControlTouchDragOutside 阈值作为框架?

string - 如何将货币字符串转换为数值?

iphone - 如何刷新 iPhone 中的 NSLocale?

Java - 如何从整数(金钱)中获取 double

iphone - 如何在打开应用程序时将第一个 viewController 屏幕设置为默认打开屏幕