2013年6月19日 星期三

Objective-C 祕技:撥完電話回到APP,讓你不會回不去。

Jie的懶教學,今天來告訴大家一個祕技:

Objective-C 呼叫電話撥號功能通常都會使用:tel
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",@"0928123123"]]];
但播完就會停留在電話程式裡...

若改成:telprompt
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt:%@",@"0928123123"]]];
結束就可以回到原本的APP畫面,

瑞凡,我可以回去了!

懶人就是要一行就搞定~完工,爆肝!

2013年6月14日 星期五

Objective-C 開啓 Google Map App 並帶入經緯度查詢

Jie的懶教學,來教大家用 Objective-C 開啓 Google Map App 並帶入經緯度查詢:

//檢查有無安裝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(太簡單,略)
}

其他進一步設定可以參考:https://developers.google.com/maps/documentation/ios/urlscheme?hl=zh-TW 

完工,爆肝。

下載Facebook影片線上工具

http://www.downvids.net/

2013年6月10日 星期一

Blogger內文貼程式碼工具


http://formatmysourcecode.blogspot.tw/

Jie的懶教學:Android Http通訊協定資料存取 (GET,POST)

Jie的懶教學,這次來教大家來寫一隻Android的懶人HttpClient程式:

在Android使用Http通訊協定(GET,POST)讀取網頁或做資料存取的時候,
每次都要做一堆try catch處理
POST的時後設定的NameValuePair形態使用也不太習慣,
基本上POST的形態都是字串,所以接口乾脆直接改成用HashMap<String,String>來設定感覺比較親切些。

當然最重要的原因還是懶,懶人就是要想盡辦法一行就搞定:D


懶人前:
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);

回傳的result字串可能是HTML,XML或JSON,就視狀況去處理啦~

完工,爆肝。

2013年6月7日 星期五

Android 專案需要網路請求時要記得加上 INTERNET Permission


在AndroidManifest.xml裡加上:

<uses-permission
android:name="android.permission.INTERNET" />

Android 專案拿掉 TitleBar 的方法


修改AndroidManifest.xml裡的theme設定:
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"

Xcode 建立 Static Library 支援 Universal Framework

Jie的懶教學,來教大家來包無敵的懶人包 Framework

1.下載解壓縮:iOS-Universal-Framework=>https://github.com/kstenerud/iOS-Universal-Framework

2.安裝Fake Framework、Real Framework,終端機進入各別目錄:輸入sh install.sh 安裝。

3.建立專案,選擇 Framework & LIbrary → Fake Static iOS Framework 樣板,
把程式拉入專案。

4.選擇TARGETS → Build Phases → Copy Headers,將.h檔拉入Public區塊裡。

5.Scheme 的 Run 設定,把 Build Configuration 改為 Release,沒改編譯會爆炸。

6.編譯完,Products 目錄裡的XXX.framework按下滑鼠右鍵,選擇 Show in Finder。

7.無embed資源的選XXX.framework,有embed資源的選 XXX.embeddedframework。

8.完工,爆肝。

WebService for Objective C

測試後發現好像只支援 2.0 的格式

https://code.google.com/p/wsdl2objc/

iPhone-AR-Toolkit 擴增實境套件

擴增實境套件,設定經緯度後可以在相機上顯示地點。

fluidUI 線上App UI 設計工具


https://www.fluidui.com/

Google Map API 查出經緯度&導航範例

經緯度:
http://maps.googleapis.com/maps/api/geocode/json?address=[地點]&sensor=false

導航
http://maps.googleapis.com/maps/api/directions/json?origin=[起點]&waypoints=[終點]&sensor=false

Icon Slayer 線上製作App Icon好用工具


可以產生各種尺寸 for App

http://www.gieson.com/Library/projects/utilities/icon_slayer/#.UbFKvPY9pv5