2009-07-28 11 views
1

ライブ通貨為替レートをiPhoneアプリにリンクするにはどうすればよいですか?まず、誰が私が為替レートを得ることができるサイトを知っていますか?そして2番目に、私はそれを私のアプリにどのようにリンクさせるのですか?私はこのアプリが何をしたいのですか?コールのhttp://the-dream.co.uk/currencee/更新されたライブ為替レートはどこで確認できますか?

+0

興味のある通貨については、その印刷銀行のサイトでレートを調べてください。 – none

答えて

1

ここではblog postですが、TBXMLを使用する場合は、以下の方法で行うことができます。

  1. あなたは(1.0の値)
  2. 通話基本料金としてexchangeRates
  3. セットのEURと呼ばれるクラスのプロパティとして可変辞書オブジェクトを作ったとします

    彼らは、次の操作を行います欧州中央銀行の為替レートのXMLフィードとそれを解析します。

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

ありがとう、これは多くの助けになりました! – Anonymous

+0

ここでもOpenExchangeRates.orgを参照してください:[openexchangerates.org](http://openexchangerates.org/) – Leafy

0

私の最初のポートは、パブリックAPIで為替レートを提供してWebサービスを見つけることであろう。 次に、必要な情報を得るために、APIと通信するアプリにいくつかの機能を統合する必要があります。

RSSフィードまたは類似した飼料中の為替レートを提供する一部のサービスがあるかもしれません。そのフィードからダウンロードしたXMLを解析して、アプリで使用できるいくつかのオブジェクトにすることができます。

+0

さて、私はRSSで1つを見つけました。言ってやるがいい。今日の通貨はbla blaだ。私はどのようにして通貨を得るのではなく、「今日の通貨は? – Anonymous

1

私はこの質問を実現既に回答済みですが、この同じ問題の解決策を探している他の人にとっては、openexchangerates.orgでも利用できる素晴らしいJSONソリューションもあります。

関連する問題