iOS開發經驗總結一

來源:互聯網
上載者:User

標籤:services   方式   企業   開啟   cti   ios 開發   cat   crash   alert   

1、使用%zd列印NSInteger ,%tu列印NSUInteger

2、UIScrollView在iOS7中使用了Autolayout導致不能滾動,方法是添加scrollview的content高度

3、UICollectionView的資料不夠,無法滑動,解決方案:tableview的資料無論多少,它的介面預設都是可以滑動的,和tableview相比collectionview的資料較少不夠一個螢幕是它無法滑動collectionview.alwaysBounceVertical=YES;設定總能垂直滑動就行。

4、直接ios7的連續跳轉

-(void)back

{

[self dismissViewControllerAnimated:YES completion:^{

if([weakself.navigationController popViewControllerAnimated:YES]){

}

}];
}

5、ios8以後用WKWebView代替UIWebView,ios8之前使用UIWebView進行html的展示,使用UIWebView存在記憶體佔用過大並不釋放問題。WKWebView解決記憶體佔用過大問題

6、企業認證下載版本可在APP中直接開啟,在APP中有H5的頁面,可以直接點擊進行其他應用的下載

7、URL轉碼問題,

stringByAddingPercentEscapesUsingEncoding,ios9版本中需要使用

stringByAddingPercentEncodingWithAllowedCharacters替代之前stringByAddingPercentEscapesUsingEncoding。

8、iOS 開發,工程中混合使用 ARC 和非ARC

Xcode 項目中我們可以使用 ARC 和非 ARC 的混合模式。

如果你的項目使用的非 ARC 模式,則為 ARC 模式的代碼檔案加入 -fobjc-arc 標籤。

如果你的項目使用的是 ARC 模式,則為非 ARC 模式的代碼檔案加入 -fno-objc-arc 標籤。

添加標籤的方法:開啟:你的target -> Build Phases -> Compile Sources 2、雙擊對應的 *.m 檔案 3、在快顯視窗中輸入上面提到的標籤 -fobjc-arc / -fno-objc-arc 4、點擊 done 儲存

9、

分享的時候注意大小

text 的大小必須 大於0 小於 10k

image 必須 小於 64k

url 必須 大於 0k

10、APNS推送

推送的 pem 檔案的產生:

pem 認證是伺服器向蘋果伺服器做推送時候需要的檔案。

  • 開啟 Keychain Access,在 Certificates 裡面找到推送的認證。

  • 分別將 certificate 和 private key 匯出得到.p12 檔案。例如:

Apple Development Push Services > Export “Apple Development Push Services ID123”,儲存為 apns-dev-cert.p12。 對“Private Key”做同樣操作,儲存為 apns-dev-key.p12 檔案。

? 需要通過終端命令將這些檔案轉換為 PEM 格式:
openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -inapns-dev-cert.p12
openssl pkcs12 -nocerts -out apns-dev-key.pem -inapns-dev-key.p12
此處要求輸入一個密碼,輸入 123456.

  • 移除密碼(上面的 123456)
    openssl rsa -in apns-dev-key.pem -out apns-dev-key.pem

  • 最後,你需要將鍵和許可檔案合成為 apns-dev.pem 檔案,此檔案在串連到 APNS 時需要使用:
    cat apns-dev-cert.pem apns-dev-key.pem > apns-dev.pem

    同樣 Distribution Certificate 的 pem 檔案產生方式一樣。
    openssl pkcs12 -clcerts -nokeys -out apns-dis-cert.pem -inapns-dis-cert.p12
    openssl pkcs12 -nocerts -out apns-dis-key.pem -in apns-dis-key.p12openssl rsa -in apns-dis-key.pem -out apns-dis-key.pem
    cat apns-dis-cert.pem apns-dis-key.pem > apns-dis.pem 

// IOS8 新系統需要使用新的代碼咯

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)

{

    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings 

     settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge)      

categories:nil]];

 

 

    [[UIApplication sharedApplication] registerForRemoteNotifications];

}

else

{

//這裡還是原來的代碼

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:

     (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];

}

原本在IOS7當中 判斷PUSH是否開啟的方法是:

UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

return (types & UIRemoteNotificationTypeAlert);

 

 

如果將這段代碼使用在 IOS當中,雖然不會出現crash的現象,但是基本沒什麼作用。

在IOS8中,我們使用如下的新代碼來取代以上的代碼

 

 

{

UIRemoteNotificationType types;

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)

   {

 types = [[UIApplication sharedApplication] currentUserNotificationSettings].types;

    }

else

   {

 types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

    }

 

 

return (types & UIRemoteNotificationTypeAlert);

}

iOS開發經驗總結一

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.