iOS Development --- UIWebView Replacement Friends League Shares SDK Update (WeChat Unverified Application Problem)

background

ShareSDK v7.0.3 (update date: June 16, 2020)

Recently, I received an email every time I updated the version. After receiving it several times in a row, I decided to put this matter (replacing UIWebView with WKWebView) on the agenda. After the simple replacement of UIWebView in the display page is completed, the next task is to update the SDK.

1. AFNetworking update (it seems that the current version is still 3.0, haha...);

2. Umeng SDK update, including statistics SDK and ShareSDK.

This blog mainly records the problems encountered when updating ShareSDK and some things that need attention.

1. Download SDK

1. Social sharing SDK

2. U-Share integrated documentation

There are several key points in the documentation:

[1], In fact, the issue about replacing UIWebView with WKWebView in the v6.9.7 version of the SDK has been updated.

 

[2], this is the main problem I encountered during the update. I think many friends must have encountered it too! ! ! ! It will be written in detail below.

2. WeChat official documents 

WeChat official documentation (update instructions for openSDK1.8.6)

iOS FAQ

 apple-app-site-association  verification is correct

[1], In order for the WeChat terminal to respond to your program after it is started, your ID must be registered with the WeChat terminal in the code. (As shown in the figure below, register the id with WeChat in the didFinishLaunchingWithOptions function of AppDelegate).

/**
#import "WXApi.h"
*/
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //向微信注册
    [WXApi registerApp:APP_ID universalLink:UNIVERSAL_LINK];
    return YES;
}

 

[2], use the SDK self-check function to troubleshoot access problems

In SDK version 1.8.7, WXApi adds a new self-check function checkUniversalLinkReady: to help developers troubleshoot problems encountered during the SDK access process.

Precautions:

Before calling the self-test function, you must first call the registerApp:universalLink interface and confirm that the call is successful. Log will be generated during the self-checking process. You can call the startLogByLevel function first to troubleshoot the problem based on the Log. The block will be called back multiple times. It is only used for debugging when newly connected to the SDK. Please do not call it in the official environment .
Sample code:

//在register之前打开log, 后续可以根据log排查问题
[WXApi startLogByLevel:WXLogLevelDetail logBlock:^(NSString *log) {
    NSLog(@"WeChatSDK: %@", log);
}];

//务必在调用自检函数前注册
[WXApi registerApp:APP_ID universalLink:UNIVERSAL_LINK];

//调用自检函数
[WXApi checkUniversalLinkReady:^(WXULCheckStep step, WXCheckULStepResult* result) {
    NSLog(@"%@, %u, %@, %@", @(step), result.success, result.errorInfo, result.suggestion);
}];

WXULCheckStep value description:

step = WXULCheckStepParams: Parameter check
step = WXULCheckStepSystemVersion: Current system version check
step = WXULCheckStepWechatVersion: WeChat client version check
step = WXULCheckStepSDKInnerOperation: WeChat SDK internal operation check step
= WXULCheckStepLaunchWechat: App launches WeChat check
step = WXULCheckStepBackToCurrentApp: Returns the current App from WeChat Check
step = WXULCheckStepFinal: The final check
will call back these 7 steps in sequence. When WXULCheckStepFinal is called back, it means that the test passes and the SDK is successfully connected. If the result.success of any step callback is NO, the process is terminated and there will be no subsequent callbacks. You can check the cause of the current step error according to result.errorInfo and fix the problem according to result.suggestion.

3. Configure Universal Link

Because of the requirements of the WeChat open platform , Universal Link must be configured, otherwise iOS13 cannot use WeChat sharing and payment functions.

Company domain name: www.ABCD.com

Configure Associated Domains in the project: applinks:www.ABCD.com

In the apple-app-site-association file, paths are configured as: "paths": [ "/app/*"]. Note that * (asterisk wildcard character) must be added after it.

Configure Universal Links in WeChat open platform: https://www.ABCD.com/app/

When registering WeChat in the project: https://www.ABCD.com/app/

1. Open the Associated Domains domain in the project

applinks: followed by your domain name, for example applinks: help.wechat.com

2. Create apple-app-site-association file

Create a file named apple-app-site-association in json format. Note that this file must have no suffix and the file name must be apple-app-site-association.

We all know that the Team ID of each developer account is unique, and the Bundle ID of each App is unique. Then the question arises: How should the same apple-app-site-association file need to be adapted to multiple Apps at the same time? deal with?

The solution is to distinguish the app ID while also paying attention to the need to configure different paths. Otherwise, when the device installs multiple applications at the same time, a jump exception will occur after the sharing is completed. The reason is that when the sharing is completed, the jump back is done through paths. Decide which App should be returned.

If the paths configured in the two appIDs are exactly the same, it will appear:
Application A → Initiate sharing → Jump to WeChat → Select friends/moments to send → Jump back to Application B. The
ideal situation should be:
Application A → Initiate sharing → Jump to WeChat→Select a friend/moment circle to send→Jump back to App A

{
    "applinks": {
        "apps": [],
        "details": [
            {
                "appID": "TeamID.BundleID1",
                "paths": [ "/wx_conn/app1/*", "/qq_conn/10000001/*"]
            },
            {
                "appID": "TeamID.BundleI2",
                "paths": [ "/wx_conn/app2/*", "/qq_conn/10000002/*"]
            }
        ]
    }
}
{
    "applinks": {
        "apps": [],
        "details": [
            {
                "appID": "HQH47S9JSQ.help.wechat.com",
                "paths": [ "/app/*" ]
            }
        ]
    }
}

details: is an array, multiple apps can be configured;

appID: your Team ID+BundleID, separated by .;

paths: The path spliced ​​after the domain name. Query parameters cannot be included. When WeChat uses Universal Links to launch a third-party App, the path and parameters will be spliced ​​at the end of Universal Links. Therefore, the paths configured by the App must be added with the wildcard /*, as configured by WeChat. For example, Universal Links is https://help.wechat.com/app

3. Upload the apple-app-site-association file

Give the apple-app-site-association file you just created to your server-side partner and place it in the root directory of the server or in the .well-known folder. Apple will first look for it in the .well-known folder. If it is not found, it will download it from the directory.

Another saying is that before iOS9.3, it was in the root directory: https://www.ABCD.com/apple-app-site-association , and after iOS9.3, it was in the .well-known directory: https:/ /www.ABCD.com/.well-known/apple-app-site-association .

File path, choose one of the two (without any suffix):

https://help.wechat.com/apple-app-site-association

https://help.wechat.com/.well-known/apple-app-site-association

4. Check whether the apple-app-site-association file is uploaded successfully

App Search API Validation Tool

5. Verify Universal Links

1>Safari browser verification

    Enter https://www.ABCD.com/app/ in the browser, for example, enter https://help.wechat.com/app . Be sure to pull down after opening the website. There will be a pop-up window similar to this. Click to open it. Jump directly to the APP.

2>Memo verification

Open the memo and enter https://www.ABCD.com/app/, for example, enter https://help.wechat.com/app . Clicking will jump directly to your own app, or long pressing will pop up a window  in "app" Open.

6. WeChat open platform configures Universal Links

      WeChat requires the format to start with https and end with "/", so fill in https://help.wechat.com/app/

7. AppDelegate configuration

1>, in Xcode, add weixin and weixinULAPI in "LSApplicationQueriesSchemes" in the "info" tab bar (as shown in the figure below).

 

 2>, registration and self-test functions

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    #ifdef DEBUG
    /*在register之前打开log, 后续可以根据log排查问题*/
    [WXApi startLogByLevel:WXLogLevelDetail logBlock:^(NSString *log) {
        NSLog(@"WeChatSDK: %@", log);
    }];
    #endif

    // 向微信注册
    [WXApi registerApp:kWXAppID universalLink:kUniversalLinks];
    
    #ifdef DEBUG
    /*调用自检函数(支付或者分享成功之后要删除这个方法,不然会导致会每次打开app都会与微信进行关联)*/
    [WXApi checkUniversalLinkReady:^(WXULCheckStep step, WXCheckULStepResult* result) {
         NSLog(@"---------%@, %u, %@, %@", @(step), result.success, result.errorInfo, result.suggestion);
    }];
    #endif
}

/*
打印如下:说明是OK的!!
app[14232:3095208] ---------0, 1, check passed,
app[14232:3095208] ---------1, 1, check passed,
app[14232:3095208] ---------2, 1, check passed,
app[14232:3095208] ---------3, 1, check passed, 
app[14232:3095208] ---------4, 1, check passed,
app[14232:3095208] ---------5, 1, Universal Link check passed. The application is launched by WeChat via Universal Link,
app[14232:3095208] ---------6, 1, All Check Passed!,
*/

3>, callback test:

When the APP is called up by UniversalLink, you can use the following methods in the delegate to perform corresponding processing and obtain relevant paths information, etc. (WeChat's processing method is used here).

// 通用链接会调用
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray<id<UIUserActivityRestoring>> * __nullable restorableObjects))restorationHandler {
    if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
        NSURL *webpageURL = userActivity.webpageURL;
        if ([webpageURL.absoluteString isEqualToString:kUniversalLinks]) {
            // 如果UniversalLinks跳转 会到这里
            NSLog(@"%@",webpageURL);
        } else {
            [[UIApplication sharedApplication]openURL:webpageURL];
        }
    }
    return [WXApi handleOpenUniversalLink:userActivity delegate:self];
}

4>, if you are calling Umeng Sharing, remember to configure 

-(void)confitUShareSettings{
    //配置微信平台的Universal Links
    //微信和QQ完整版会校验合法的universalLink,不设置会在初始化平台失败
    [UMSocialGlobal shareInstance].universalLinkDic = @{@(UMSocialPlatformType_WechatSession):TCUMUnivernalLink};
}

important point

  1. If everything is configured correctly and you still can't launch the app, delete the app and reinstall it.
  2. If everything is configured, you can share and log in with WeChat, but "Unverified Applications" will still appear. This is because the list of unverified applications is not updated in real time. Only the new SDK (version 1.8.6 or above) was connected the day before and there is If the record is called correctly, it will be removed from the list the next day, and the number of correct shares on the previous day is more than 10 times.
  3. After adding the test function checkUniversalLinkReady, it will jump to WeChat every time it is started, and then jump back to the app. Commenting it out will no longer jump to WeChat.

related articles

(SDK) - Update WeChat open platform openSDK1.8.6

iOS WeChat openSDK uses Universal Links to fill pitfalls

Universal Link--apple-app-site-association file problem

IOS configurationUniversal Links

Guess you like

Origin blog.csdn.net/jiaxin_1105/article/details/107565476