Just My Life & My Work

Archive for the ‘iOS’ Category

[iOS] Base64 編碼解碼 (Base64 Encoding Decoding)

先前已經研究果Base64編碼的原理,現在以iOS來實作看看⋯⋯

/**
 Theme: Base64 Encoding Decoding
 IDE: Xcode 7
 Language: Objective C
 Date: 104/10/16
 Author: HappyMan
 Blog: https://cg2010studio.wordpress.com/
 */
    NSString *plainString = @"HappyMan";
    
// Encoding
    NSData *plainData = [plainString dataUsingEncoding:NSUTF8StringEncoding];
    NSString *base64String = [plainData base64EncodedStringWithOptions:0];
    NSLog(@"%@", base64String); // SGFwcHlNYW4=
    
// Decoding
    NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:base64String options:0];
    NSString *decodedString = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding];
    NSLog(@"%@", decodedString); // HappyMan

原來這麼簡單XD~

Base64 chart Base64 Man Base64 HappyMan

參考:Base64 Decoding in iOS 7+

[iOS] Code Signing 問題

我以為是因為安裝最新的Xcode 7,才會讓Provision遺失,後來經資深工程師提點,才知道原來是Provision過期,所以要重新過期,所以要重新喚醒下載使用。再來又發現Certificate也要一起更新下載使用⋯⋯

Provision deadline

No codesigning identities (i.e. certificate and private key pairs) that match the provisioning profile specified in your build settings (“iOS Team Provisioning Profile: *”) were found.

Xcode can attempt to fix this issue. This will reset your code signing and provisioning settings to recommended values and resolve issues with signing identities and provisioning profiles.

(繼續閱讀…)

[iOS][watchOS] 位元代碼 (Bitcode)

還沒看到有高人翻譯,所以我暫且稱之為位元代碼 (Bitcode),看來我被中國化了⋯⋯台灣用語應為位元程式碼!其實在WWDC 2015,Apple只是提到它,並沒有詳細介紹它架構與運作,謎樣地描述什麼是位元代碼 (Bitcode):

Bitcode is an intermediate representation of a compiled program. Apps you upload to iTunes Connect that contain bitcode will be compiled and linked on the App Store. Including bitcode will allow Apple to re-optimize your app binary in the future without the need to submit a new version of your app to the store.

Xcode hides symbols generated during build time by default, so they are not readable by Apple. Only if you choose to include symbols when uploading your app to iTunes Connect would the symbols be sent to Apple. You must include symbols to receive crash reports from Apple.

Note: For iOS apps, bitcode is the default, but optional. If you provide bitcode, all apps and frameworks in the app bundle need to include bitcode. For watchOS apps, bitcode is required.

如果以圖示來描繪是:

bitcode

(繼續閱讀…)

[iOS] Facebook SDK 取得帳號資料

現代人已經離不開臉書,大部分的人每天黏在臉書獲取資訊與互動朋友,於是會有許多資料放在臉書中,因而成為其它服務平台的媒介,減少重複輸入個人資料的行為,於是一鍵登入我們很熟悉!同時方便使用者開發者

Facebook SDK login

這是Facebook SDK內建的按鈕樣式

(繼續閱讀…)

[iOS] 判斷App在前景或背景

收到推播時有兩種狀況:

  • 前景 (Foreground)
  • 背景 (Background)

push notification from background

(繼續閱讀…)

[iOS] 視圖除錯 (View Debugging)

寫完程式就會來測試除錯,過去幾乎都只能在字裡行間找出臭蟲,現在拜Xcode之賜,可以視覺化來視圖除錯 (View Debugging)!這對所有設計使用者介面的工程師來說可是相當棒,因為設備只有一個螢幕,每個畫面都會塞滿視覺元件,等待使用者與其互動後來變化視覺元件,很多時候我們以為這些元件非常正常地運行,然而因為看不見就以為真的沒問題,呵~多虧現在裝置規格非常之高,所以稍微過度使用也無傷大雅!

view debugging animation

(繼續閱讀…)

[iOS] 介面陰影效果 (UI Shadow Effect)

想讓介面看起來更加立體,不用再等設計師出圖囉~只要是簡單的陰影效果,我們可以直接使用程式碼做出效果來!

程式碼非常簡單,我是在cell上的cellView做陰影,可以設定顏色、半徑、透明度、位置等等,原本是白色黏在底部,套用後變成漂浮在上頭。

    cell.cellView.layer.shadowColor = [[UIColor blackColor] CGColor];
    cell.cellView.layer.shadowRadius = 2.0;
    cell.cellView.layer.shadowOpacity = 0.3;
    cell.cellView.layer.shadowOffset = CGSizeMake(0.0, 2.0);

原始樣子:

iOS 介面陰影 UI Shadow

應用效果:

iOS 介面陰影 UI Shadow2

有空就美化一下介面吧!該凸的就凸,該凹的就凹,會很吸引眾人的目光:P~

[iOS] 刪除所有檔案與資料夾 (Delete all File and Folder)

有時候需要刪除所有檔案與資料夾 (Delete all File and Folder),來重新下載檔案,因為有可能下載來的檔案是壞掉的。

Delete all file and folder2

(繼續閱讀…)

[iOS][watchOS] Phone與Watch溝通

來到watchOS2的時代,除了Watch可以獨立運行外,與Phone溝通也變得比較容易,透過全新的WatchConnectivity framework,就能彼此溝通呢!於是就不用像watchOS1時代拐彎抹角囉~

Watch Connectivity00001

(繼續閱讀…)

[iOS] 自訂性質 (Customize Property)

我們自己定義的類別當然可以自訂性質 (Customize Property),但是若是SDK內建的類別,繼承其類別來自訂性質可就不建議,不過我們有特殊作法!

聽聽神人怎麼說:

The Cocoa frameworks take the approach that the Object Composition pattern is more appropriate than traditional class hierarchy.

In general, this means that there is likely to be a property on UIButton where you can set another object to handle various aspects of the button. This is the preferred way to “customize" how your button works.

One of the main reasons for this pattern is that many library components create buttons and don’t know that you want them to create instances of your subclass.

(繼續閱讀…)

標籤雲