2016年1月13日 星期三

iOS Bolts with AFNetworking Batch Request


Bolts-iOS is a Manage task libary by Facebook and Parse.
To solved async callbacks problem like  Promise Pattern.

When we need request batch use AFNetworking with bolts to manage request task.
Here is some sample code.

First use async BFTask to create request.
 @property (nonatomic, strong) AFHTTPSessionManager *manager;  
 - (BFTask *) executeEndPointAsync :(NSString *)url parameters:(id)parameters {  
   BFTaskCompletionSource *BFTask = [BFTaskCompletionSource taskCompletionSource];  
    AFHTTPResponseSerializer *responseSerializer = [AFJSONResponseSerializer serializer];  
   self.manager.responseSerializer = responseSerializer;  
   [self.manager GET:url parameters:parameters progress:^(NSProgress * _Nonnull downloadProgress) {  
   } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {  
     //do something, save response   
     [BFTask setResult:responseObject];  
   } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {  
     [BFTask setError:error];  
   }];  
   return BFTask.task;  
 }  

And then run with executeEndPointAsync

 - (void)runTask{  
   [[[BFTask taskWithResult:nil]continueWithBlock:^id _Nullable(BFTask * _Nonnull task) {  
     BFTask *subTask = [BFTask taskWithResult:nil];  
     for (int i = 0; i < 100; i++) {  
       subTask = [subTask continueWithBlock:^id(BFTask * subTask) {  
         if (subTask.isCancelled) {  
         }else if(subTask.error){  
         }else{  
           //do http request  
           return [self executeEndPointAsync:@"http://..." parameters:nil];  
         }  
         return nil;  
       }];  
     }  
     return subTask;  
   }]continueWithSuccessBlock:^id _Nullable(BFTask * _Nonnull task) {  
     NSLog(@"Success");  
     return nil;  
   }];  
 }  


2016年1月12日 星期二

iOS UIWebView throw exception in runtime

While some JS will called webkit method,resulted in iOS unrecognized method.

[WebActionDisablingCALayerDelegate willBeRemoved]: unrecognized selector sent to instance

[WebActionDisablingCALayerDelegate removeFromSuperview]: unrecognized selector sent to instance

So I provided method in runtime,

+ (void)load{
Class class = NSClassFromString(@"WebActionDisablingCALayerDelegate");
SEL willBeRemoved = @selector(willBeRemoved);
class_addMethod(class, willBeRemoved, (IMP)willBeImplementation, nil);
}

void willBeImplementation(id self, SEL _cmd) {

}

While webkit call [WebActionDisablingCALayerDelegate willBeRemoved],
it was replaced by willBeImplementation.
 

2015年10月5日 星期一

Xcode 7 New Features for Test Code Coverage

Step 1.
Open Xcode Schemes










Step 2.
Select Test scheme



Step 3.

Checked Code Coverage


Step 4.
Run test and select report  navigator,
choose testing report,select coverage tab.
It will show code coverage.



Steop 5.
See coverage range for test
double chick coverage,it will show running times for test report.


2015年8月17日 星期一

Parse background job issue

When using  parse background job,
if loops which saving object are too many,which resulted in interrupted.
Solved: Use Parse.object.saveAll,it can save large data once only.

2014年12月9日 星期二

iOS Reject Reasons by 2.23


2.23: Apps must follow the iOS Data Storage Guidelines or they will be rejected

We found that your app does not follow the iOS Data Storage Guidelines, which is required per the App Store Review Guidelines.

In particular, we found that on launch and/or content download, your app stores XX.XX MB. To check how much data your app is storing:

- Install and launch your app
- Go to Settings > iCloud > Storage & Backup > Manage Storage
- If necessary, tap "Show all apps"
- Check your app's storage

The iOS Data Storage Guidelines indicate that only content that the user creates using your app, e.g., documents, new files, edits, etc., should be backed up by iCloud.

Temporary files used by your app should only be stored in the /tmp directory; please remember to delete the files stored in this location when the user exits the app.

Data that can be recreated but must persist for proper functioning of your app - or because customers expect it to be available for offline use - should be marked with the "do not back up" attribute. For NSURL objects, add the NSURLIsExcludedFromBackupKey attribute to prevent the corresponding file from being backed up. For CFURLRef objects, use the corresponding kCFURLIsExcludedFromBackupKey attribute.

For more information, please see Technical Q&A 1719: How do I prevent files from being backed up to iCloud and iTunes?.

solution: Disable iCloudBackUp or Move File to tmp

Disable iCloudBackUP 
By Apple Stackoverflow
In App Launch
NSString *docsDir;
NSArray *dirPaths;
NSURL * finalURL;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
finalURL = [NSURL fileURLWithPath:docsDir];
[self addSkipBackupAttributeToItemAtURL:finalURL] 
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL {
    assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);
    NSError *error = nil;
    BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]forKey: NSURLIsExcludedFromBackupKey error: &error];
    if(!success){
        NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
        
    }
    return success;
}

2014年12月8日 星期一

Git useful command

  • git init
  • git clone
  • git status
    • Look untracked file & changes not staged for commit & changes to be commit up 
  • git diff
  • git add
    • add FILE to stage area
    • git add [FILE-NAME]
    • git add -A
    • git add .
  • git reset
    • Rset stage or commit
    • git reset [PATH]
    • git reset --soft/hard
    • git reset .
  • git checkout
    • checkout to commit or branch
    • git checkout [BRANCH]
    • git checkout [COMMIT-HASH]
    • git checkout [PATH]
  • git commit
    • change commit log
    • git commit --allow-empty
    • git commit -a
    • git commit -m
  • git log
  • git branch
    • git branch [NEW-BRANCH-NAME]
    • git branch -d/D [BRANCH]
    • git branch -m [PATH/NEW-NAME]
    • git branch -a
  • git merge
    • git merge
    • git merge --no-ff
  • git revert
    • git revert [COMMIT]
    • git revert -m1 [COMMIT-OF-MERGE]
  • git rebase
    • git rebase [BRANCH]
    • git rebase -i [COMMIT]
  • git push
    • git push --tags
    • git push [REMOTE] [BRANCH]
    • git push [REMOTE] :[BRANCH]
  • git pull
  • git stash
    • git stash list
    • git stash apply
    • git stash pop
    • git stash clear
  • git tag
    • git tag [NAME]
    • git tag -m [MESSAGE] [NAME]
    • git tag -d
    • git tag -n1
  • git clean
    • git clean -df
  • git flow command
    • git flow init
    • git flow feature start [SOME Feature]
    • git flow hotfix start [SOME Version]
    • git flow release start [SOME Version]
    • git flow feature finish [SOME Feature]
    • start (will new branch from develop currently commit)
    • finish (will merge branch to production and develop branches in release&hotfix , but finish feature branch only merge to develop branch)
  • IF need CI ,Suggest to use CMake flow. 

2014年11月28日 星期五

Node.js with Mongodb

Node.js which is popular server-side networking applications,
it has high performance on real-time web.
Mongodb which is NOSQL database,has document-oriented,ad hoc queries,indexing,replication,load balancing,file storage,aggregation,server-side JavaScript execution and capped collections.It matches with node.js application.
There is some step to install node.js with mongodb.

We use node-mongodb-native
Here is github link

1. Install Mongodb with Homebrew
$ brew install mongodb

2. Create the data directory
$ mkdit -p /data/db

3. Install NodeJS Driver
Under package.json file directory
$ npm install

4.Booting up a MongoDB Server
$ sudo mongod --dbpath=/data/db --port 27017