2015年3月22日 星期日

AFNetworking HTTP delete 傳送json字串


在呼叫delete之前


先加上

manager.requestSerializer.HTTPMethodsEncodingParametersInURI = [NSSet setWithObjects:@"GET", @"HEAD", nil];
即可送出時帶json字串

2015年1月18日 星期日

電子發票QRcode 規格 說明

其實只是金額是16進位,導致找很久...

二、規格
二維條碼應以 QR Code 形式記載,數量二個,以左右水平配置,編碼區長
寬各 1.5 公分以上,其周圍應至少各保留 0.2 公分 (±10%)以上之空白處。記載
事項含發票字軌、發票開立日期 (年月日)、四位隨機碼、銷售額、總計額、發票
買方統一編號、發票開立賣方統一編號、加密驗證資訊、營業人自行使用區、二
維條碼記載完整品目筆數、該張發票交易品目總筆數、中文編碼參數、品名、數
量、單價、補充說明。詳細內容如下:
(一) 左方二維條碼記載事項:
1. 發票字軌 (10 位):記錄發票完整十碼號碼。
2. 發票開立日期 (7 位):記錄發票三碼民國年、二碼月份、二碼日期。
3. 隨機碼 (4 位):記錄發票上隨機碼四碼。
4. 銷售額 (8 位):記錄發票上未稅之金額總計八碼,將金額轉換以十六進
位方式記載。若營業人銷售系統無法順利將稅項分離計算,則以
00000000 記載。
5. 總計額 (8 位):記錄發票上含稅總金額總計八碼,將金額轉換以十六進
位方式記載。
6. 買方統一編號 (8 位):記錄發票上買受人統一編號,若買受人為一般消
費者則以 00000000 記載。
7. 賣方統一編號 (8 位):記錄發票上賣方統一編號。
8. 加密驗證資訊 (24 位):將發票字軌十碼及隨機碼四碼以字串方式合併
後使用 AES 加密並採用 Base64 編碼轉換。
以上欄位總計 77 碼。下述資訊為接續以上資訊繼續延伸記錄,且每個
欄位前皆以間隔符號“:”(冒號)區隔各記載事項,若左方二維條碼不敷記載,
則繼續記載於右方二維條碼。
9. 營業人自行使用區 (10 位):提供營業人自行放置所需資訊,若不使用則
以 10 個“*”符號呈現。
10.二維條碼記載完整品目筆數:記錄左右兩個二維條碼記載消費品目筆
數,以十進位方式記載。2
11.該張發票交易品目總筆數:記錄該張發票記載總消費品目筆數,以十進
位方式記載。
12.中文編碼參數 (1 位):定義後續資訊的編碼規格,若以:
(1) Big5 編碼,則此值為 0
(2) UTF-8 編碼,則此值為 1
(3) Base64 編碼,則此值為 2
編碼資訊包含從第一個品名前的間隔符號後的所有資訊(品名、數量、單
價、補充說明),且不包含右方二維條碼前兩碼起始符號。
未來視辦理狀況,將僅開放 UTF-8 編碼規格。
接續之品名、數量、單價為重覆循環呈現至所有品目記載完成,若品
目筆數過多以致左右兩個二維條碼無法全部記載,則以記載最多可放置於
左右兩個二維條碼內容之品目為原則。
13.品名:商品名稱,請避免使用間隔符號“:”(冒號)於品名。
14.數量:商品數量,在中文編碼前,以十進位方式記載。
15.單價:商品單價,在中文編碼前,以十進位方式記載。
16.補充說明:非必要使用資訊,營業人可自行選擇是否運用,於左右兩個
二維條碼已記載所有品目資訊後,始可使用此空間。長度不限。
(二) 右方二維條碼記載事項:
1. 右方二維條碼前兩碼起始符號 (2 位):首 2 碼固定以“**”為起始符號,
供未來讀取端辨識左方或右方二維條碼之用。
2. 接續左方二維條碼不敷記載之中文編碼後資訊

參考:
https://www.einvoice.nat.gov.tw/home/Article!showArticleDetail?articleId=1394532945159&CSRT=15856240287845357006

2014年9月29日 星期一

XCode 6 下 Autolayout 的使用下 UICollectionViewCell 在ios8正常 但是在ios7會變形

在使用Autolayout的時候,會發生ios8顯示正常,但是執行在ios7下會出現畫面跑調的問題,那解決方法如下

此為ios8的執行結果:                                      

此為ios7的執行結果:


可以看到本來在photo的地方應該要被autolayout下他的height會變成0但是沒有。


在你customCell.m內新增加以下程式:

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    BOOL contentViewIsAutoresized = CGSizeEqualToSize(self.frame.size, self.contentView.frame.size);
    
    if( !contentViewIsAutoresized) {
        CGRect contentViewFrame = self.contentView.frame;
        contentViewFrame.size = self.frame.size;
        self.contentView.frame = contentViewFrame;
    }
}

UITableView 或 UICollectionView在有照片的時候可以 asynch 圖片 asynch photo image


 在顯示UITableView 或 UICollectionView 要一起帶入有圖檔的時候,可以先把畫面顯示出來之後,在去下載圖片並顯示出來,方法如下:

要先新增一個class ImageRequest 繼承NSMutableURLRequest

ImageRequest.h


#import 

#define kIMAGE_REQUEST_CACHE_LIMIT  100
typedef void (^CompletionBlock) (UIImage *, NSError *);

@interface ImageRequest : NSMutableURLRequest

- (UIImage *)cachedResult;
- (void)startWithCompletion:(CompletionBlock)completion;
@end


ImageRequest.m

#import "ImageRequest.h"

NSMutableDictionary *_inflight;
NSCache *_imageCache;

@implementation ImageRequest

- (NSMutableDictionary *)inflight {
    
    if (!_inflight) {
        _inflight = [NSMutableDictionary dictionary];
    }
    return _inflight;
}

- (NSCache *)imageCache {
    
    if (!_imageCache) {
        _imageCache = [[NSCache alloc] init];
        _imageCache.countLimit = kIMAGE_REQUEST_CACHE_LIMIT;
    }
    return _imageCache;
}

- (UIImage *)cachedResult {
    
    return [self.imageCache objectForKey:self];
}

- (void)startWithCompletion:(CompletionBlock)completion {
    
    UIImage *image = [self cachedResult];
    if (image) return completion(image, nil);
    
    NSMutableArray *inflightCompletionBlocks = [self.inflight objectForKey:self];
    if (inflightCompletionBlocks) {
        // a matching request is in flight, keep the completion block to run when we're finished
        [inflightCompletionBlocks addObject:completion];
    } else {
        [self.inflight setObject:[NSMutableArray arrayWithObject:completion] forKey:self];
        
        [NSURLConnection sendAsynchronousRequest:self queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
            if (!error) {
                // build an image, cache the result and run completion blocks for this request
                UIImage *image = [UIImage imageWithData:data];
                [self.imageCache setObject:image forKey:self];
                
                id value = [self.inflight objectForKey:self];
                [self.inflight removeObjectForKey:self];
                
                for (CompletionBlock block in (NSMutableArray *)value) {
                    block(image, nil);
                }
            } else {
                [self.inflight removeObjectForKey:self];
                completion(nil, error);
            }
        }];
    }
}


@end

在UICollectionView上使用的時候

  
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
                  cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];

    NSURL *url = [NSURL URLWithString:@"http:// some url from your model"];
    // note that this can be a web url or file url

    ImageRequest *request = [[ImageRequest alloc] initWithURL:url];

    UIImage *image = [request cachedResult];
    if (image) {
        UIImageView *imageView = (UIImageView *)[cell viewWithTag:127];
        imageView.image = image;
    } else {
        [request startWithCompletion:^(UIImage *image, NSError *error) {
            if (image && [[collectionView indexPathsForVisibleItems] containsObject:indexPath]) {
                [collectionView reloadItemsAtIndexPaths:@[indexPath]];
            }
        }];
    }
    cell.photoView.image = image;

    return cell;
}
出處:
http://stackoverflow.com/questions/15799432/poor-uicollectionview-scrolling-performance-with-uiimage/15799771#15799771

UIScrollView 滑動到最下方增加資料 scrollView scroll to the end add data


在UITableView與UICollection的時候可以透過滑動到最下面的時候去更新資料

透過UIScrollView的delegate來實現


- (void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    float bottomEdge = scrollView.contentOffset.y + scrollView.frame.size.height;
    if (bottomEdge >= scrollView.contentSize.height)  {
        //更新資料的動作
        [self callApi];
        //呼叫loading畫面
        [UIView animateWithDuration:0.5
                              delay:0
                            options:UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionBeginFromCurrentState
                         animations:^{
                             self.endLoadingView.hidden = NO;
                             CGRect frame = self.endLoadingView.frame;
                             frame.origin.y += CGRectGetHeight(frame);
                             self.endLoadingView.frame = frame;
                             frame.origin.y -= CGRectGetHeight(frame);
                             self.endLoadingView.frame = frame;
 
                         }
                         completion:NULL];
        
        
        
    }
}