優缺點分析參考文章:http://www.alexplay.tw/2013/03/udid.html
https://github.com/ylechelle/OpenUDID
取得OpenUDID方式:
#include "OpenUDID.h"
NSString* openUDID = [OpenUDID value];
#include "OpenUDID.h"
NSString* openUDID = [OpenUDID value];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",@"0928123123"]]];
但播完就會停留在電話程式裡...[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt:%@",@"0928123123"]]];
結束就可以回到原本的APP畫面,-(void)prepareForReuse{
[super prepareForReuse];
//清除舊資料
delegate = nil;
}
//檢查有無安裝google map
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]){
//開啓Google Map App
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"comgooglemaps://?saddr=%f,%f&daddr=%f,%f&directionsmode=walking",起點latitude,起點longitude,終點latitude,終點longitude]]];
}else{
//開啟網頁版Google Map(太簡單,略)
}
package com.example.jiehttpclient;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class JieHttpClient {
public static String GET(String url){
String result = "";
HttpGet get = new HttpGet(url);
try {
HttpClient httpClient = new DefaultHttpClient();
HttpResponse httpResponse = httpClient.execute(get);
if(httpResponse.getStatusLine().getStatusCode()== HttpStatus.SC_OK){
result = EntityUtils.toString(httpResponse.getEntity());
}else{
result = "JieHttpClient GET Fail";
}
}catch(ClientProtocolException e){
System.out.println("JieHttpClient GET Error = "+e.getMessage().toString());
}catch (IOException e){
System.out.println("JieHttpClient GET Error = "+e.getMessage().toString());
}catch (Exception e){
System.out.println("JieHttpClient GET Error = "+e.getMessage().toString());
}
return result;
}
public static String POST(String url,HashMap<String,String> paramsMap){
String result = "";
HttpPost post = new HttpPost(url);
try {
if(paramsMap!=null){
List<NameValuePair> params = new ArrayList<NameValuePair>();
for(Map.Entry<String,String> entry:paramsMap.entrySet()){
params.add(new BasicNameValuePair(entry.getKey(),entry.getValue()));
}
HttpEntity httpEntity = new UrlEncodedFormEntity(params,"utf-8");
post.setEntity(httpEntity);
}
HttpClient httpClient = new DefaultHttpClient();
HttpResponse httpResponse = httpClient.execute(post);
if(httpResponse.getStatusLine().getStatusCode()== HttpStatus.SC_OK){
result = EntityUtils.toString(httpResponse.getEntity());
}else{
result = "JieHttpClient POST Fail";
}
}catch(ClientProtocolException e){
System.out.println("JieHttpClient POST Error = " + e.getMessage().toString());
}catch (IOException e){
System.out.println("JieHttpClient POST Error = " + e.getMessage().toString());
}catch (Exception e){
System.out.println("JieHttpClient POST Error = " + e.getMessage().toString());
}
return result;
}
}
//GET
String result = JieHttpClient.GET("GET URL");
//POST
HashMap<String,String> params = new HashMap<String, String>();
params.put("key1","value1");
params.put("key2","value2");
String result = JieHttpClient.POST("POST URL",params);