<熊貓車(chē)幫>項(xiàng)目總結(jié)

自己總結(jié),歡迎指正,不喜勿噴

2017.03.05-2017.05.23

1.動(dòng)態(tài)更改collectionView的頭部視圖

self.flowLayout.headerReferenceSize = CGSizeMake(kMainScreenWidth, Size(540));//把布局申明為屬性,動(dòng)態(tài)更改header的高度

2.如何實(shí)現(xiàn)按鈕左圖右字

//左圖右字,同理可得上圖下字
- (void) rightSetting:(NSString *)title ImageN:(NSString *)image {
    [self.rightButton setTitle:title forState:UIControlStateNormal];
    [self.rightButton setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    self.rightButton.imageView.size = CGSizeMake(Size(28), Size(40));
    self.rightButton.size = CGSizeMake(Size(135), Size(40));
    self.rightButton.titleLabel.backgroundColor = self.rightButton.backgroundColor;
    self.rightButton.imageView.backgroundColor = self.rightButton.backgroundColor;
    //在使用一次titleLabel和imageView后才能正確獲取titleSize
    CGSize titleSize = self.rightButton.titleLabel.bounds.size;
    CGSize imageSize = self.rightButton.imageView.bounds.size;
    CGFloat interval = Size(3);
    self.rightButton.imageEdgeInsets = UIEdgeInsetsMake(0,titleSize.width + interval, 0, -(titleSize.width + interval));
    self.rightButton.titleEdgeInsets = UIEdgeInsetsMake(0, -(imageSize.width + interval), 0, imageSize.width + interval);
}

3.重置下拉刷新完畢狀態(tài)

[strongSelf.collectionView.mj_footer resetNoMoreData];

4.如何實(shí)現(xiàn)應(yīng)用外導(dǎo)航

參考鏈接

//還需在info.plist里添加白名單:
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>comgooglemaps</string> //谷歌地圖
    <string>iosamap</string>         //高德地圖
    <string>baidumap</string>        //百度地圖
</array>
//下面是彈出相應(yīng)地圖的彈框方法:需要傳經(jīng)緯度和目的地名
+ (void)presentMap:(UIViewController *)fatherVC  Coordinate:(CLLocationCoordinate2D)coordinates Name:(NSString *)toName
{
    __block NSString *urlScheme = @"TheDrivingCloudStuentSchemes";
    __block NSString *appName = @"熊貓車(chē)幫";
    __block CLLocationCoordinate2D coordinate = coordinates;
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    //這個(gè)判斷其實(shí)是不需要的
    if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"http://maps.apple.com/"]])
    {
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"蘋(píng)果地圖" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            
            MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
            MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil]];
            if (![toName isEqualToString:@""]) {
                toLocation.name = toName;
            }
            
            [MKMapItem openMapsWithItems:@[currentLocation, toLocation]
                           launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}];
        }];
        
        [alert addAction:action];
    }
    
    if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]])
    {
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"百度地圖" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            
            NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name=目的地&mode=driving&coord_type=gcj02",coordinate.latitude, coordinate.longitude]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:nil];
            
        }];
        
        [alert addAction:action];
    }
    
    if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]])
    {
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"高德地圖" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            
            NSString *urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication=%@&backScheme=%@&lat=%f&lon=%f&dev=0&style=2",appName,urlScheme,coordinate.latitude, coordinate.longitude]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:nil];
            
        }];
        
        [alert addAction:action];
    }
    
    if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]])
    {
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"谷歌地圖" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            
            NSString *urlString = [[NSString stringWithFormat:@"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%f,%f&directionsmode=driving",appName,urlScheme,coordinate.latitude, coordinate.longitude]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            
           [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:nil];
            
        }];
        
        [alert addAction:action];
    }
    
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alert addAction:action];
    
    [fatherVC presentViewController:alert animated:YES completion:^{
        
    }];
}

5.七牛云如何截圖

//后面增加如下子串:
model.avatar = [model.avatar stringByAppendingString:@"?imageView2/1/w/200/h/200"];
//上傳圖片
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyyMMddHHmmss";
    NSString *imageName = [NSString stringWithFormat:@"zt%@",[formatter stringFromDate:[NSDate date]]];
    NSString *token = [[NSUserDefaults standardUserDefaults]objectForKey:k_Qiniu_Token];
    QNUploadManager *upManager = [[QNUploadManager alloc] init];
    NSData *imageData = UIImageJPEGRepresentation(image, 1);
    __weak typeof (self) weakSelf = self;
    [upManager putData:imageData key:imageName token:token
              complete: ^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
                  __strong typeof(self) strongSelf = weakSelf;
                  if (info.isOK) {
                      strongSelf.avaterURL = [NSString stringWithFormat:@"%@%@",strongSelf.avaterDomain,key];
                      [strongSelf postDataFouncation];
                  }else {
                      [YFWLHUDManager dismiss];
                      strongSelf.bgView.hidden = YES;
                      [YFWLHUDManager showFailureMessage:@"網(wǎng)絡(luò)錯(cuò)誤" duration:1.3];
                  }
              } option:nil];

6.判斷是否開(kāi)啟了某系統(tǒng)功能

參考鏈接

#pragma mark - 判斷是否開(kāi)啟了定位功能
- (void) judgeLocation {
    if ([CLLocationManager locationServicesEnabled] &&
        ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized
         || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined)) {
            //定位功能可用,開(kāi)始定位
            [self AmapInitSetting];
        } else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
             NSString *version = [UIDevice currentDevice].systemVersion;
            if (version.doubleValue >= 10.0) {
                [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
            }else{
                NSURL *url = [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"];
                if ([[UIApplication sharedApplication] canOpenURL:url]){
                    [[UIApplication sharedApplication] openURL:url];
                }
            }
        }
}

7.把json文件轉(zhuǎn)換成對(duì)應(yīng)的json數(shù)據(jù)

- (id) loadDataFouncation:(NSString *)name TypeN:(NSString *)type {
    NSString *jsonPath = [[NSBundle mainBundle] pathForResource:name ofType:type];
    NSData *data = [NSData dataWithContentsOfFile:jsonPath];
    NSError *error = nil;
    return [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
}

8.json字符串和字典數(shù)組的相互轉(zhuǎn)換

1.將字典或者數(shù)組轉(zhuǎn)化為JSON串
- (NSData *)toJSONData:(id)theData{
    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:theData options:NSJSONWritingPrettyPrinted  error:&error];
    if ([jsonData length] > 0 && error == nil){
        return jsonData;
    }else{
        return nil;
    }
}
2.json格式字符串轉(zhuǎn)數(shù)組:
-  (id)toArrayOrNSDictionary:(NSData *)jsonData{
    NSError *error = nil;
    id jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:nil];
    if (jsonObject != nil && error == nil){
        return jsonObject;
    }else{
        // 解析錯(cuò)誤
        return nil;
    }
}

9.如何加載html格式的web

- (void) loadRequestString{
    UIWebView* webView = [[UIWebView alloc]initWithFrame:self.view.bounds];
    //webView.scalesPageToFit = YES;//自動(dòng)對(duì)頁(yè)面進(jìn)行縮放以適應(yīng)屏幕
    webView.delegate = self;
    [self.view addSubview:webView];
    NSString *htmlString = [[NSUserDefaults standardUserDefaults]objectForKey:self.htmlStr];
    //根據(jù)網(wǎng)頁(yè)提供的字體改變網(wǎng)頁(yè)中的字體效果
    //htmlString = [htmlString stringByReplacingOccurrencesOfString:@"tx-font#" withString:@"24"];
    [webView loadHTMLString:htmlString baseURL:nil];
}

#pragma mark - UIWebViewDelegate
- (void)webViewDidStartLoad:(UIWebView *)webView{
    [YFWLHUDManager showMessage:@"加載中,請(qǐng)稍候"];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
    [YFWLHUDManager dismiss];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    [YFWLHUDManager showFailureMessage:@"加載失敗" duration:1.3];
}

10.如何給彈框加上輸入框

//alert為自定義的UIAlertController
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
    __strong typeof(self) strongSelf = weakSelf;
    textField.placeholder = @"請(qǐng)輸入金額(不大于可提現(xiàn)傭金)";
    textField.font = [UIFont systemFontOfSize:Size(28)];
    textField.textColor = [UIColor colorWithRGB:color(212121)];
    textField.keyboardType = UIKeyboardTypeDecimalPad;
    textField.delegate = strongSelf;
    [textField becomeFirstResponder];
}];

11.如何檢測(cè)網(wǎng)絡(luò)狀況

 //監(jiān)測(cè)當(dāng)前網(wǎng)絡(luò)狀況:直接把代碼加載在如下方法里就能時(shí)刻監(jiān)測(cè)網(wǎng)絡(luò),并做相應(yīng)處理
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    __weak typeof (self) weakSelf = self;
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        __strong typeof(self) strongSelf = weakSelf;
        if(status ==AFNetworkReachabilityStatusReachableViaWWAN || status == AFNetworkReachabilityStatusReachableViaWiFi){
        }else{
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"溫馨提示" message:@"當(dāng)前無(wú)網(wǎng)絡(luò)連接" delegate:strongSelf cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
            alert.delegate = strongSelf;
            [alert show];
        }
    }];
 }

12.獲取路徑和判斷文件是否存在

//判斷文件是否存在
- (BOOL)isSxistAtPath:(NSString *)filePath{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL isExist = [fileManager fileExistsAtPath:filePath];
    return isExist;
}
//獲取document路徑
- (NSString *)getDocumentsPath{
    return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,    NSUserDomainMask, YES) firstObject];
}

13.將json模型對(duì)象存入文件

- (BOOL)writeFile:(NSString *)fileName WithModel:(YFWLQuestionOneModel *)model{
    NSData *resultData = [NSJSONSerialization dataWithJSONObject:[model mj_keyValues] options:NSJSONWritingPrettyPrinted error:nil];
    NSString *iosPath = [NSString stringWithFormat:@"%@/%@",[self getDocumentsPath],fileName];
    BOOL result = [resultData writeToFile:iosPath atomically:YES];
    return result;
}

14.文件操作之拷貝已有文件

- (void)copyFromFile:(NSString *)sourcePath  toOutPath:(NSString *)outPath{
    NSFileHandle *infile, *outfile; //輸入文件、輸出文件
    NSData *buffer = [[NSData alloc]init]; //讀取的緩沖數(shù)據(jù)
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *iosOutPath = [NSString stringWithFormat:@"%@/%@",[self getDocumentsPath],outPath];
    BOOL success  = [fileManager createFileAtPath:iosOutPath contents:nil attributes:nil];
    if (!success){
        return;
    }
    NSString *iosSourcePath = [NSString stringWithFormat:@"%@/%@",[self getDocumentsPath],sourcePath];
    infile = [NSFileHandle fileHandleForReadingAtPath:iosSourcePath]; //創(chuàng)建讀取源路徑文件
    if (infile == nil){
        return;
    }
    outfile = [NSFileHandle fileHandleForWritingAtPath:iosOutPath]; //創(chuàng)建并打開(kāi)要輸出的文件
    if (outfile == nil){
        return;
    }
    [outfile truncateFileAtOffset:0]; //將輸出文件的長(zhǎng)度設(shè)為0
    buffer = [infile readDataToEndOfFile];  //讀取數(shù)據(jù)
    [outfile writeData:buffer];  //寫(xiě)入輸入
    [infile closeFile];       // 關(guān)閉寫(xiě)入、輸入文件
    [outfile closeFile];
}

15.刪除沙盒里的文件

// 刪除沙盒里的文件
-(void)deleteFile:(NSString *)fileName {
    NSFileManager* fileManager=[NSFileManager defaultManager];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    //文件名
    NSString *uniquePath=[[paths objectAtIndex:0] stringByAppendingPathComponent:fileName];
    BOOL blHave=[[NSFileManager defaultManager] fileExistsAtPath:uniquePath];
    if (!blHave) {
        return ;
    }else {
        BOOL blDele= [fileManager removeItemAtPath:uniquePath error:nil];
        if (blDele) {
            NSLog(@"dele success");
        }else {
            NSLog(@"dele fail");
        }
    }
}

16.清除所有NSUserDefault的對(duì)象

NSUserDefaults *defatluts = [NSUserDefaults standardUserDefaults];
NSDictionary *dictionary = [defatluts dictionaryRepresentation];
for(NSString *key in [dictionary allKeys]){
    [defatluts removeObjectForKey:key]; 
    [defatluts synchronize];
}

17.模型轉(zhuǎn)對(duì)象,數(shù)組轉(zhuǎn)對(duì)象(MJExtension框架)

//數(shù)組轉(zhuǎn)對(duì)象
+ (NSDictionary *)mj_objectClassInArray {
    return @{@"data" : [YFWLBannerArray class]};
}
//替換更改屬性
+ (NSDictionary *)mj_replacedKeyFromPropertyName {
    return @{@"idField" : @"id"};
}

18.極光推送

集成文檔

// 取得 APNs 標(biāo)準(zhǔn)信息內(nèi)容
NSDictionary *notification = [launchOptions objectForKey:   UIApplicationLaunchOptionsRemoteNotificationKey];
NSDictionary *aps = [notification valueForKey:@"aps"];
NSString *content = [aps valueForKey:@"alert"]; //推送顯示的內(nèi)容
NSInteger badge = [[aps valueForKey:@"badge"] integerValue]; //badge數(shù)量
NSString *sound = [aps valueForKey:@"sound"]; //播放的聲音
// 取得Extras字段內(nèi)容
NSString *customizeField1 = [userInfo valueForKey:@"customizeExtras"]; //服務(wù)端中Extras字段,key是自己定義的

19.融云IM

文檔很好,跟著集成就行了 集成文檔

//此方法中要提供給融云用戶(hù)的信息,建議緩存到本地,然后改方法每次從您的緩存返回
//融云不管理用戶(hù)信息,用戶(hù)信息需要從上個(gè)界面?zhèn)鬟^(guò)來(lái),或者后臺(tái)獲取
- (void)getUserInfoWithUserId:(NSString *)userId completion:(void(^)(RCUserInfo* userInfo))completion{
    if ([[[RCIM sharedRCIM]currentUserInfo].userId isEqual:userId]) {
        RCUserInfo *user = [[RCUserInfo alloc]init];
        user.userId = [[RCIM sharedRCIM]currentUserInfo].userId;
        user.name = [[NSUserDefaults standardUserDefaults]objectForKey:k_User_Name];
        user.portraitUri = [[NSUserDefaults standardUserDefaults]objectForKey:k_User_HeadImage];
        return completion(user);
    }else if([self.targetId isEqual:userId]) {
        RCUserInfo *user = [[RCUserInfo alloc]init];
        user.userId = self.targetId;
        user.name = self.titleName;
        user.portraitUri = self.headUrl;
        return completion(user);
    }
}

20. 友盟分享

集成文檔
注:微信的應(yīng)用需要去申請(qǐng)上線才能測(cè)試分享,所以提前去申請(qǐng)好

//如何添加自定義的分享按鈕
[UMSocialUIManager addCustomPlatformWithoutFilted:UMSocialPlatformType_UserDefine_Begin+2 withPlatformIcon:[UIImage imageNamed:@"YF_2面對(duì)面分享"] withPlatformName:@"面對(duì)面分享"];
    [UMSocialShareUIConfig shareInstance].sharePageGroupViewConfig.sharePageGroupViewPostionType = UMSocialSharePageGroupViewPositionType_Bottom;
    [UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageItemStyleType = UMSocialPlatformItemViewBackgroudType_IconAndBGRadius;
    [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
        __strong typeof(self) strongSelf = weakSelf;
        //在回調(diào)里面獲得點(diǎn)擊的
        if (platformType == UMSocialPlatformType_UserDefine_Begin+2) {
            __weak typeof (self) weakSelf = self;
            [UIView animateWithDuration:0.3 delay:0.2 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                __strong typeof(self) strongSelf = weakSelf;
                strongSelf.QrCodeView.transform = CGAffineTransformMakeTranslation(0, -Size(666));
            } completion:nil];
        }
        else{
            [strongSelf shareWebPageToPlatformType:platformType];
        }
    }];

21. 高德地圖

定位集成文檔
注:高德的定位只返回了標(biāo)準(zhǔn)的區(qū)域編碼,一般規(guī)律取區(qū)域編碼的前四位后面添零:即是城市編碼,取區(qū)域編碼的前兩位后面添零:即是省編碼。

22. 支付寶支付

APP支付集成文檔
坑少:跟著文檔走,加簽分后臺(tái)和前臺(tái),不過(guò)新版都要求后臺(tái)傳,做的時(shí)候跟后臺(tái)一起注意驗(yàn)證參數(shù),簽名之類(lèi)。

//請(qǐng)求了后臺(tái)接口獲取相應(yīng)簽名后調(diào)用的支付方法
- (void) aliPayWithMessage:(NSString *)orderStr {
    // NOTE: 如果加簽成功,則繼續(xù)執(zhí)行支付
    if (orderStr != nil) {
        //應(yīng)用注冊(cè)scheme,在AliSDKDemo-Info.plist定義URL types
        NSString *appScheme = k_App_Scheme;
        // NOTE: 調(diào)用支付結(jié)果開(kāi)始支付
        [[AlipaySDK defaultService] payOrder:orderStr fromScheme:appScheme callback:^(NSDictionary *resultDic) {
            NSLog(@"***************reslut = %@",resultDic);
        }];
    }else {
        [YFWLHUDManager showFailureMessage:@"獲取訂單失敗" duration:1.4];
    }
}
// 支付跳轉(zhuǎn)支付寶錢(qián)包進(jìn)行支付,處理支付結(jié)果
[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
        __strong typeof(self) strongSelf = weakSelf;
        [strongSelf presentAlert:resultDic[@"resultStatus"] Message:resultDic[@"memo"]];
 }];
    
// 授權(quán)跳轉(zhuǎn)支付寶錢(qián)包進(jìn)行支付,處理支付結(jié)果:以下都是在AppDelegate中處理
[[AlipaySDK defaultService] processAuth_V2Result:url standbyCallback:^(NSDictionary *resultDic) {
    NSLog(@"result = %@",resultDic);
    // 解析 auth code
    NSString *result = resultDic[@"result"];
    NSString *authCode = nil;
    if (result.length>0) {
        NSArray *resultArr = [result componentsSeparatedByString:@"&"];
        for (NSString *subResult in resultArr) {
            if (subResult.length > 10 && [subResult hasPrefix:@"auth_code="]) {
                authCode = [subResult substringFromIndex:10];
                break;
            }
        }
    }
    NSLog(@"授權(quán)結(jié)果 authCode = %@", authCode?:@"");
}];

//出來(lái)支付結(jié)果
- (void) presentAlert:(NSString *)status Message:(NSString *)message {
NSString *content = message;
switch ([status integerValue]) {
    case 9000:
        content = @"支付成功";
        break;
    case 8000:
        content = @"正在處理中";
        break;
    case 4000:
        content = @"訂單支付失敗";
        break;
    case 5000:
        content = @"訂單重復(fù)支付";
        break;
    case 6001:
        content = @"已取消";
        break;
    case 6002:
        content = @"網(wǎng)絡(luò)連接出錯(cuò)";
        break;
    default:
            break;
    }
    if (content == nil || [content isEqualToString:@""]) {
        content = @"發(fā)生未知錯(cuò)誤";
    }
    [self presentAlert:content];//彈出相應(yīng)提示,或者發(fā)送通知做界面展示
}

23. 微信支付

微信的支付文檔啥的就不說(shuō)了,集成過(guò)的都知道??犹啵⊥瑫r(shí)必須微信官方審核過(guò)了才能驗(yàn)證支付,應(yīng)用必須申請(qǐng)上線,必須開(kāi)通支付能力。前面一堆建議優(yōu)先級(jí)為最高,不然,后面時(shí)間不夠,審核很慢。
參考文檔1
參考文檔2(推薦)

//請(qǐng)求了后臺(tái)接口獲取相應(yīng)簽名后調(diào)用的支付方法,參數(shù)必須一一對(duì)應(yīng)
- (void) doWeixinPay:(YFWLWexinPayModel *)model {
    if (model == nil) {
        [YFWLHUDManager showFailureMessage:@"獲取訂單失敗" duration:1.4];
        return;
    }
    PayReq *request = [[PayReq alloc] init];
    request.partnerId = model.partnerid;
    request.prepayId  = model.prepayid;
    request.package   = model.package_sign;
    request.nonceStr  = model.noncestr;
    request.timeStamp = model.timestamp;
    request.sign= model.sign;
    [WXApi sendReq:request];
}

//微信支付回調(diào):處理支付結(jié)果:以下都是在AppDelegate中處理
-(void)onResp:(BaseResp*)resp{
    if ([resp isKindOfClass:[PayResp class]]){
        PayResp*response=(PayResp*)resp;
        NSLog(@"支付失敗,retcode = %d errStr = %@",resp.errCode,resp.errStr);
        NSString *message = @"未知結(jié)果";
        switch(response.errCode){
            case 0:
                message = @"支付成功";
                break;
            case -1:
                message = @"支付錯(cuò)誤";
                break;
            case -2:
                message = @"用戶(hù)取消";
                break;
            default:
                break;
        }
        [self presentAlert:message]; //彈出相應(yīng)提示,或者發(fā)送通知做界面展示
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 227,837評(píng)論 6 531
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 98,196評(píng)論 3 414
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人,你說(shuō)我怎么就攤上這事。” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 175,688評(píng)論 0 373
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我,道長(zhǎng),這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 62,654評(píng)論 1 309
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 71,456評(píng)論 6 406
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 54,955評(píng)論 1 321
  • 那天,我揣著相機(jī)與錄音,去河邊找鬼。 笑死,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,044評(píng)論 3 440
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 42,195評(píng)論 0 287
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 48,725評(píng)論 1 333
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 40,608評(píng)論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 42,802評(píng)論 1 369
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,318評(píng)論 5 358
  • 正文 年R本政府宣布,位于F島的核電站,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 44,048評(píng)論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 34,422評(píng)論 0 26
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 35,673評(píng)論 1 281
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 51,424評(píng)論 3 390
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 47,762評(píng)論 2 372

推薦閱讀更多精彩內(nèi)容