1.啟動IDE(如Xcode)女嘲,把iOS包中的壓縮文件中以下文件拷貝到項目文件夾下,并導(dǎo)入到項目工程中
????? AlipaySDK.bundle; AlipaySDK.framework
在Build Phases選項卡的Link Binary With Libraries中添履,增加以下依賴:
其中,需要注意的是:
如果是Xcode 7.0之后的版本凉驻,需要添加libc++.tbd贝淤、libz.tbd;
如果是Xcode 7.0之前的版本郭计,需要添加libc++.dylib霸琴、libz.dylib
2.AppDelegate.m中引入頭文件 < #import <AlipaySDK/AlipaySDK.h>>
//9.0前的方法,為了適配低版本 保留
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
???????? if ([url.host isEqualToString:@"safepay"]) {
?????????????? //跳轉(zhuǎn)支付寶錢包進(jìn)行支付昭伸,處理支付結(jié)果
????????????? [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary??? *resultDic) {
?????????????????????? NSLog(@"result = %@",resultDic);
????????????? }];
?????????? }
??????????? return YES;
}
//9.0后的方法
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options{
(://pay 之前的那串字符串就是你的APPID梧乘,)
??????????? if ([url.host isEqualToString:@"safepay"]) {
????? ?? ? // 支付跳轉(zhuǎn)支付寶錢包進(jìn)行支付,處理支付結(jié)果
???????? ? ? ? ? ?? [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
????????????? ? ? ? ? ? ? ? ?? NSLog(@"result = %@",resultDic);
??????? ? ? ? ? ? ? }];
?? ? ? ? ?? }
????????? return YES;
}
3.在發(fā)起支付的頁面
?????? 3.1 先請求后臺獲取支付信息和簽名信息庐杨;
?????? 3.2 調(diào)用:
???? ? ? ? ?? [[AlipaySDK defaultService] payOrder:returnData[@"payeeOrder"][@"payInfo"] fromScheme:@"com.vivebest.paymd"callback:^(NSDictionary *resultDic) {
????????????????????????? QLLog(@"reslut = %@",resultDic);
????????????? }];
??????? 3.3 在info中配置scheme选调,與參數(shù)中傳遞的要一致
4.有可能遇到的坑
坑1: 我遇到的問題是做聚合支付的sdk的時候需要集成支付寶支付功能
??????? 導(dǎo)入了AlipaySDK.framework和bundle 文件,但添加第三方依賴庫libz.tbd和libc++.tbd的時候就會包編譯報錯Xcode 版本是8.2 ,iOS 項目是動態(tài)庫(打包給別人使用),導(dǎo)入了AlipaySDK.framework和bundle 文件,但添加第三方依賴庫libz.tbd和libc++.tbd的時候就會包編譯報錯
error: /Users/mac/Downloads/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Users/mac/Downloads/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.2.sdk/usr/lib/libc.tbd is not an object file (not allowed in a library)
然后嘗試谷歌上面一些做法:
1.Delete all references to .tbd files from either your linked libraries phase, or from the copied bundle resources phase (where they sometimes will be added).
Go to Build Phases >Link Binary with Librairies > + > Add other -> Add a library to your project, then click 'Add Other...' then press Shift+Command+G and type in the path '/usr/lib' - you'll find libz.dylib there.
add "-lz" to the other linker flags
這個是網(wǎng)絡(luò)上面的一些方法,試過也沒法實現(xiàn),項目使用Aggregate來打包,導(dǎo)進(jìn)一個app里面使用的會報這種異常
Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_AlipaySDK", referenced from:
objc-class-ref in LocalSDK(LocalHttpHelper.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
這個錯誤是不是跟這兩個 libz.tbd和libc++.tbd 有關(guān) ?
解決辦法:第三方支付寶庫不參加打包即可,在app中引用灵份。
坑2: 引入支付寶 缺少 #include<openssl/asn1.h>報錯
解決方法:在 Building Settings -> Search Paths -> Header Search Paths 里添加 openssl/asn1.h(因為openssl/asn1.h就在這個文件夾里) 的路徑進(jìn)去就可以了