iOS開発-微信の簡単なテキスト共有(公式SDKを統合)

12899 ワード

前言
開発ツール:XCode 7.3.1 SDKバージョン:V 1.7.1
一.APP提出審査
前期準備:このブログを参考にすることができますhttp://www.jianshu.com/p/839dc30f2250iOSバージョンではBundle Idを提供するだけで済みます
iOS开发 - 微信之简单文本分享(集成官方SDK)_第1张图片
500CD4E3-4EE2-449F-8BF6-32D3102D1605.png
注意:ダウンロードアドレスの適用は必須ではありません
承認後にAppID、AppSecretを取得できます
iOS开发 - 微信之简单文本分享(集成官方SDK)_第2张图片
appid.png
二.環境構築
1.最新のSDKをダウンロード
ダウンロードアドレスhttps://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419319164&token=fdf6c5d38e9c82f85ebf72374441beff257c4849&lang=zh_CN
iOS开发 - 微信之简单文本分享(集成官方SDK)_第3张图片
iOSリソースのダウンロードpng
2.SDKのインポート
iOS开发 - 微信之简单文本分享(集成官方SDK)_第4张图片
SDKをインポートする.png
3.プロジェクト構成
a.HTTPリクエストをサポートする設定
iOS开发 - 微信之简单文本分享(集成官方SDK)_第5张图片
HTTPリクエストをサポートする.png
参考文献:http://www.jianshu.com/p/5935dff47e4f
b.shemeホワイトリストの設定
iOS开发 - 微信之简单文本分享(集成官方SDK)_第6张图片
Schemeホワイトリストを設定します.png
参考文献:http://www.jianshu.com/p/f974f4cbba18
c.bitcodeを閉じる
iOS开发 - 微信之简单文本分享(集成官方SDK)_第7张图片
bitcode 1を無効にする.png

bitcode 2を無効にする.png
d.URLの設定
iOS开发 - 微信之简单文本分享(集成官方SDK)_第8张图片
URLを設定します.png
e.Build phasesの設定
iOS开发 - 微信之简单文本分享(集成官方SDK)_第9张图片
Build phasesを設定します.png
三.コード統合
1.登録ID、コールバック処理
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

//          
NSString *APPID = @"         AppID";
//      
[WXApi registerApp:APPID];

return YES;
}

-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
return [WXApi handleOpenURL:url delegate:self];
}

-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options{
return [WXApi handleOpenURL:url delegate:self];
}

#pragma mark WXApiDelegate          

// onReq               ,         。             sendRsp  。   sendRsp   ,            
- (void)onReq:(BaseReq *)req
{
NSLog(@"onReq               ,         。             sendRsp  。   sendRsp   ,            ");
}

//              sendReq   ,  onResp    。sendReq     ,           
- (void)onResp:(BaseResp *)resp
{
NSLog(@"    ");

//           
if ([resp isKindOfClass:[SendMessageToWXResp class]]) {
    switch (resp.errCode) {
        case WXSuccess:
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"  "
                                                            message:@"    !"
                                                           delegate:self
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil, nil];
            [alert show];
        }
            break;

        default:
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"  "
                                                            message:@"    !"
                                                           delegate:self
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil, nil];
            [alert show];
        }
            break;
    }
  }
}

2.共有コアコード
//       
-(IBAction)clickShareButton:(id)sender{
SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
req.text                = @"        ";
req.bText               = YES;
//     
//          WXSceneSession
//           WXSceneTimeline
//          WXSceneFavorite
req.scene               = WXSceneSession;
[WXApi sendReq:req];
}

四.よくある質問のまとめ(出会った穴...)
1.公式Demoコンパイルエラー
ダウンロード先:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419319164&token=fdf6c5d38e9c82f85ebf72374441beff257c4849&lang=zh_CN解決策:
iOS开发 - 微信之简单文本分享(集成官方SDK)_第10张图片
解决策png
公式Demo:(公式のdemoを直接実行すると各種エラーが報告されます...、間違いのないバージョンを提供します)https://github.com/andli0626/wx_demo_for_iOS-V1.7.1.git
五.参考資料
公式ドキュメント
https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=1417694084&token=fdf6c5d38e9c82f85ebf72374441beff257c4849&lang=zh_CN
公式API更新説明:
# SDK1.7.1
1.    ipv6(     )
2. xCode Version 7.3.1 (7D1014)   
# SDK1.7
1.    ipv6
2.           
# SDK1.6.3
1.xCode7.2    sdk 。
2.   xCode7.23.    Build
Phases Link  Security.framework
4.# SDK1.6.2
1、xCode7.1   sdk 
2、   xCode7.1    
# SDK1.6.1
1、  armv7s ,bitcode      
2、  warning
# SDK1.6
1、iOS 9      ,   http     ,       “Info.plist”      URL
Schemes     ,              。
    ,      iOS9       SDK     (  、  、  、   ) ,   “Info.plist”       :
LSApplicationQueriesSchemes

weixin

NSAppTransportSecurity

NSAllowsArbitraryLoads


2、            CoreTelephony.framework
3、  bitcode      
# SDK1.5
1、  safeSendReq:  ,  sendReq:  。
2、  +(BOOL)
sendAuthReq:(SendAuthReq*) req viewController : (UIViewController*)
viewController delegate:(id) delegate;
          Auth,   WXApi.h    
3、                   ,                       。            :SystemConfiguration.framework,libz.dylib,libsqlite3.0.dylib。

実装効果図
iOS开发 - 微信之简单文本分享(集成官方SDK)_第11张图片
未命名の画像png
ソース:https://github.com/andli0626/wx_sharedemo_for_iOS-V1.7.1.git
何事も最初は難しいので、簡単なテキスト共有を完成し、後の他のAPIの使用は公式ドキュメントを参考にして、一歩一歩実践することができます.
作者:Jin牌码男
リンク:http://www.jianshu.com/p/c9b688fdb961
出典:簡書
著作権は作者の所有である.商業転載は著者に連絡して許可を得てください.非商業転載は出典を明記してください.