2015年9月2日 星期三

how to get icloud free space

從 2014年查到的舊文章看來, 是無法取得, 也許新的iOS 版本有支援.

  • Q1: What is maximum file size to upload on iCloud?
  • Q2: Can I programmatically calculate/know the available space on user's iCloud account?
  • Q3: How can I get the event for uploading and Downloading files from iCloud?


from:
http://stackoverflow.com/questions/21456210/icloud-integration-for-uploading-and-downloading-files

==============================
Although you mentioned you've read the apple icloud documentation, the designing for icloud documentation page from Apple is still a good starting point for this question.
File Size Limits
The documentation doesn't specify a Document file size limit, nor a Core Data storage limit, other than a user account icloud storage allowance. There is a limit for Key Value storage which is 1Mb for a value (in a value-key pair), which could be an issue for you, but otherwise it seems you can store large files as long as the user has enough space available.
Given the 5gb default amount and accounting for the default user storage needs (photos, contacts, calendars and the like), you may encounter limits for Document and Core Data storage, like any other app. The file management for icloud page mentions good app behaviour:
Apps that take advantage of iCloud storage features should act responsibly when storing data in there. The space available in each user’s account is limited and is shared by all apps. In addition, users can see how much space is consumed by a given app and choose to delete documents and data associated with your app. For these reasons, it is in your app’s interest to be responsible about what files you store.
Check Available Space Programmatically
No
Upload/Download Events
The file uploading and downloading is handled by the OS. All files are stored locally, it's from this local store that you request/modify/save documents. From the icloud fundamentals page:
When you adopt iCloud, the operating system initiates and manages uploading and downloading of data for the devices attached to an iCloud account. Your app does not directly communicate with iCloud servers and, in most cases, does not invoke upload or download of data.
See this app coda tutorial for an example of key-value store integration, this Tim Roadley tutorial for Core Data store integration or this Ray Wenderlich tutorial for Document store integration.
Edit: The Document-Based App Programming Guide for iOS provides code snippets for moving files to/from iCloud, uploading and downloading as well as monitoring file changes. See "Downloading Document Files from iCloud" and "Moving a Document to iCloud Storage".

2015年8月14日 星期五

ios8 share extension example

研究這篇文章:
iOS 8: How to Build a Simple Action Extension
http://code.tutsplus.com/tutorials/ios-8-how-to-build-a-simple-action-extension--cms-22794

後來找到的較佳的範例:
https://github.com/martinnormark/ShareByMail
可惜是用 swift 寫的.

Apple 官方的說明文件:
https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ShareSheet.html

Share
Share extensions give users a convenient way to share content with other entities, such as social sharing websites or upload services. For example, in an app that includes a Share button, users can choose a Share extension that represents a social sharing website and then use it to post a comment or other content.

實作時, 先遇到2個問題,
1) navigation bar, 無法放2個 action.
解法:

2) extension icon 顯示為空白的, 或是全黑.
解法:
http://stackoverflow.com/questions/28479859/ios-share-extension-post-button-title

Solution:
I found solution for my question,I removed the original navigation bar and create custom nav bar.
I have two nav bar: 1. with "cancel"\"save" buttons 2. with "back" button
and I change them when navigate to other viewcontroller (in my case I needed to upload file and user need select location from list)
NOTE: if you not implement configurationItems you need only the first nav bar. (just call to set custom nav bar from viewDidAppear
So my code is here:
@property (strong, nonatomic) UINavigationBar *customNavBar;

-(void) viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];  
    self.customNavBar = [[UINavigationBar alloc] initWithFrame:self.navigationController.navigationBar.bounds];
    [self.navigationController.navigationBar removeFromSuperview];
    [self.navigationController.view addSubview:self.customNavBar];
    [self setCancelSaveNavigationItem];
}
setCancelSaveNavigationItem--> called from viewDidAppear of shareViewController
-(void)setCancelSaveNavigationItem
{
    UINavigationItem *newItem = [[UINavigationItem alloc] init];
    UIBarButtonItem *cancelBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Cancel",nil)  style:UIBarButtonItemStylePlain target:self action:@selector(cancelButtonTapped:)];
    UIBarButtonItem *saveBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done",nil)  style:UIBarButtonItemStyleDone target:self action:@selector(saveButtonTapped:)];
    newItem.leftBarButtonItem = cancelBarButtonItem;
    newItem.rightBarButtonItem = saveBarButtonItem;
    [self.customNavBar setItems:@[newItem]];
    [self.navigationItem setBackBarButtonItem:cancelBarButtonItem];
    [self.navigationItem setRightBarButtonItem:saveBarButtonItem];
    if(self.item.value == nil){
        saveBarButtonItem.enabled = NO;
    }
}
setBackNavigationItem--> called in configurationItems -->in self.item.tapHandler function
-(void)setBackNavigationItem
{
    UINavigationItem *newItem = [[UINavigationItem alloc] init];
    UIBarButtonItem *selectBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Select",nil)  style:UIBarButtonItemStylePlain target:self action:@selector(selectButtonTapped:)];
    UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:[NSString stringWithFormat:@"❮ %@", NSLocalizedString(@"Back",nil)]  style:UIBarButtonItemStylePlain target:self action:@selector(backButtonTapped:)];
    newItem.leftBarButtonItem = backBarButtonItem;
    newItem.rightBarButtonItem = selectBarButtonItem;
    [self.customNavBar setItems:@[newItem]];
    [self.navigationItem setBackBarButtonItem:backBarButtonItem];
    [self.navigationItem setRightBarButtonItem:selectBarButtonItem];
}
Handle buttons tapped:
- (void)backButtonTapped:(id)sender {
    if([self.navigationController.viewControllers count] ==2){
        [self setCancelSaveNavigationItem];
    }
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)cancelButtonTapped:(id)sender {
    [self cancel];
}

- (void)selectButtonTapped:(id)sender {
    ...
    [self setCancelSaveNavigationItem];
    [self popConfigurationViewController];
}

- (void)saveButtonTapped:(id)sender {
    ...
    [self cancel];
}
And it's work for me!!!
The result:

enter image description here
enter image description here

結果, 第2個問題, 我使用上面的 code 還是一樣, 然後刪掉一開始 xcode 幫我拉好的  navigation bar, 重拉一個 navigation bar, 再拉一個 navigation item, 然後放進2個 bar button item 就做完了. 原來這麼簡單, 弄了半天. @_@;

iOS8 share extension icon 顯示為空白的, 或是全黑.

這個問題很多人都有遇到, 解法很簡單, 重做一張乾淨版本的ICON, 而且要 "Target Membership" 裡要勾 share extension 的新 target.



Make sure the 'Target Membership' (right side pane) of the extension icons includes both the extension target AND the app target.

Extension icons must have a fully transparent background, NOT solid white. Any white, or any colour other than transparent, will be rendered as solid dark grey.

相關文章:





2015年7月23日 星期四

ld: framework not found iCloud

下載了一個 iOS App 的範例程式: iRareMedia/iCloudDocumentSync, 作者寫:

/** iCloud Document Sync makes it easy for developers to integrate the iCloud document storage APIs into iOS applications. This is how iCloud document-storage and management should've been out of the box from Apple. Integrate iCloud into iOS (OS X coming soon) Objective-C document projects with one-line code methods. Sync, upload, manage, and remove documents to and from iCloud with only a few lines of code (compared to the hundreds of lines and hours that it usually takes). Get iCloud up and running in your iOS app in only a few minutes. Updates and more details on this project can be found on [GitHub](http://www.github.com/iRareMedia/iCloudDocumentSync). If you like the project, please star it on GitHub!  The `iCloud` class provides methods to integrate iCloud into document projects.  Adding iCloud Document Sync to your project is easy. Follow these steps below to get everything up and running.  1. Drag the iCloud Framework into your project 2. Add `#import <iCloud/iCloud.h>` to your header file(s) iCloud Document Sync 3. Subscribe to the `<iCloudDelegate>` delegate. 4. Call the following methods to setup iCloud when your app starts:  @warning Only available on iOS 6.0 and later on apps with valid code signing and entitlements. Requires Xcode 5.0.1 and later. Check the online documentation for more information on setting up iCloud in your app. */
試了很多次, 終於解決了2個問題:

  1. Build 會失敗: ld: framework not found iCloud
  2. <iCloud/iCloud.h> not found.


問題1解法:

把 "Search Paths" - "Freamework Search Paths" 加入該 framework 實際的 path.



問題2解法:

把 iCloud.h 加入project 裡, 然後把 source code 裡的  <iCloud/iCloud.h> 改為 "iCloud.h" 就OK了.


使用心得, 這個範例似乎不太穩定, 很容易掛掉, 在 debug 模式裡, 可以看到錯誤訊息, 但不知道該如何解.


相關文章:

iCloud and UIDocument: Beyond the Basics, Part 1/4
http://www.raywenderlich.com/12779/icloud-and-uidocument-beyond-the-basics-part-1






2015年7月20日 星期一

App Transport Security policy

在 iOS9 上面開發 App, 之前可以用的連線方式不能用了. 變成一定要改用 https, 或是加入例外, error messsage:
The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.

App Transport Security Technote
https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/index.html


解法: Disable App Transport Security

Add this to the Info.plist:

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>


See Apple’s App Transport Security Technote for full details (thanks @gnasher729).
You can add exceptions for specific domains in your Info.plist:
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>testdomain.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <false/>
            <key>NSExceptionAllowInsecureHTTPSLoads</key>
            <false/>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <true/>
            <key>NSExceptionMinimumTLSVersion</key>
            <string>TLSv1.2</string>
            <key>NSThirdPartyExceptionAllowInsecureHTTPSLoads</key>
            <false/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <true/>
            <key>NSThirdPartyExceptionMinimumTLSVersion</key>
            <string>TLSv1.2</string>
            <key>NSRequiresCertificateTransparency</key>
            <false/>
        </dict>

        ...

    </dict>
</dict>
All the keys for each excepted domain are optional. The speaker did not elaborate on any of the keys, but I think they’re all reasonably obvious.
You can also ignore all app transport security restrictions with a single key:
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

from:
http://stackoverflow.com/questions/30731785/how-do-i-load-an-http-url-with-app-transport-security-enabled-in-ios-9



2015年7月12日 星期日

太極刷機大師

由於需要測試 iOS 9.0 上面的新功能, 所以需要升級 iPad  到 9.0 beta 版, 試了半天, 在 Mac 上不知道怎麼弄, 也找不到工具. 後來是回到 Windows 裡安裝太極刷機大師來解決, 滿簡單的, 隨便點2下就做完了.

點 "一鍵刷機".


刷好後, 就變成 iOS 9.0 了.


檔案下載:
http://www.taigpro.com/

2015年7月9日 星期四

iOS keychain mechanism to increase password protection

從某些角度來看, 透過 keychain 並不是保護密碼的好方法.

Qfile HD 1.5.0 版本的新內容
https://itunes.apple.com/tw/app/qfile-hd/id597800201?l=zh&mt=8
Starting from this version, the password of the connected profile will use the built-in iOS keychain mechanism to increase password protection.
Please re-enter the connected profile's password before connecting to a NAS.



KeyChain優點:


  • 每個組( keychain-access-groups )之間資料存取隔離,沒有權限的app無法讀取他人資料,保證資料的安全.
  • 全域性統一儲存,即使刪除app,keychain中的資料依然存在,下次重新安裝app還能存取.
  • 存儲後的資料會加密.
  • 同一個組的app可以共享keychain中的資料.


KeyChain缺點:


  • 刪除app後不會清除keychain裡的資料,如果儲存密碼等敏感性資料有一定的風險。
  • iOS 越獄後keychain能被導出來,密碼的明碼即可被看到。



實作方法:

到GitHub下載SFHFKeychainUtils第三方套件,接著匯入到專案中。


使用範例:

#import "SFHFKeychainUtils.h"
 
// 取可以識別的名字
static NSString *const RLKeychainUserName = @"HTKeychainUserName";
static NSString *const RLKeychainServiceName = @"HTKeychainServiceName";
 
#pragma mark - Key Chain Methods
// 取得密碼
+(NSString *)loginToken
{
    return [SFHFKeychainUtils getPasswordForUsername:RLKeychainUserName andServiceName:RLKeychainServiceName error:nil];
}
 
// 設定密碼
+(void)setLoginToken:(NSString *)loginToken
{
    [SFHFKeychainUtils storeUsername:RLKeychainUserName andPassword:loginToken forServiceName:RLKeychainServiceName updateExisting:YES error:nil];
}
 
// 移除密碼
+(void)removeLoginToken
{
    [SFHFKeychainUtils deleteItemForUsername:RLKeychainUserName andServiceName:RLKeychainServiceName error:nil];
}




相關網站:





Facebook 留言