[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];
とする。
iPhone/iPod touchアプリの開発に関するメモ。 配布するアプリのプロモーション、サポートなども。
// Assume that (NSDate *)date already exists.
NSCalendar* calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
unsigned int flags = NSYearCalendarUnit |
NSMonthCalendarUnit |
NSDayCalendarUnit |
NSHourCalendarUnit |
NSMinuteCalendarUnit |
NSSecondCalendarUnit;
NSDateComponents *components = [calendar components:flags fromDate:date];
[calendar release];
// Here, you can get information about (NSDate *)date
// by using methods year, month, day, hour, minute, and second of instance (NSCalendar *)components.
[components release];
http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService // (1)などとする。なお、スペースは使えないので"%20"としていることに注意。
&AWSAccessKeyId=[Your Access Key ID] // (2)
&Operation=ItemSearch // (3)
&SearchIndex=Books // (4)
&Keywords=Harry%20Potter // (5)
#実際には一行で書く。
(1). 一行目
(2). 二行目
(3). 三行目
(4). 四行目と(5). 五行目
このリクエストに対するレスポンス
<?phpサーバ側のAmazonAWS.phpは、クライアントからのリクエストをアマゾン・Webサービスのエンドポイント(http://ecs.amazonaws.jp/onca/xml)に送り、そのレスポンスをJSONに変換してクライアントに返す。
define("KEY_ID", "Your Access Key ID");
define("ASSOCIATE_ID", "Your Associate ID");
$request = "http://ecs.amazonaws.jp/onca/xml?Service=AWSECommerceService";
$request.="&AWSAccessKeyId=".KEY_ID;
$request.="&AssociateTag=". ASSOCIATE_ID;
$request.="&Operation=ItemSearch";
$request.="&SearchIndex=" . $_GET["SearchIndex"];
$request.="&Title=" . $_GET["Title"];
$request.="&Author=" . $_GET["Author"];
$request.="&Publisher=" . $_GET["Publisher"];
$request.="&Keywords=" . $_GET["Keywords"];
$response = file_get_contents($request);
$xml = simplexml_load_string($response);
$json = json_encode($xml);
echo($json);
?>
<html>クライアントはアマゾンの商品データベースへの検索フィールドを送り、返ってきたJSON形式のレスポンスから必要な情報を抽出する。上の例では検索結果のタイトルをリストにして表示する。
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Testing Amazon Associates Web Service</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.form.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var option = {
success: function(json) {
$("#SearchResults").empty();
for (var i = 0; i < json.Items.Item.length; i++) {
$("#SearchResults")
.append(
$("<li></li>")
.html(json.Items.Item[i].ItemAttributes.Title)
);
}
},
dataType: "json"
};
$("#ajaxForm").ajaxForm(option);
});
</script>
</head>
<body>
<form id="ajaxForm" action="AmazonAWS.php" method="get">
<table>
<tr><td>タイトル</td><td><input type="text" name="Title"></td></tr>
<tr><td>著者</td><td><input type="text" name="Author"></td></tr>
<tr><td>出版社</td><td><input type="text" name="Publisher"></td></tr>
<tr><td>キーワード</td><td><input type="text" name="Keywords"></td></tr>
</table>
<input type="radio" name="SearchIndex" value="Books" checked>和書
<input type="radio" name="SearchIndex" value="ForeignBooks">洋書
<button type="submit">検索</button>
</form>
<ul id="SearchResults"></ul>
</body>
</html>