Contents

Weibo SDK 以及 BlocksKit

在项目中有这么一个场景,viewController A present 一个 B 出来,在 B 中设计了一个 UIActionSheet 选中微博则再 request 微博的授权。

[sheet bk_addButtonWithTitle:@"微博" handler:^{
    //request weibo token here
}];

在模拟器上进行测试发现无法弹出微博的网页认证,控制台打印了

CanNotAuthInWeiboApp WBAuthorizeRequest

通过 Chrome 的历史记录看到我在 21:16 分第一次搜索了该打印信息,由此开始了我查找问题的过程。

一三四链接打开研究发现是和 redirecturl 的配置相关的错,我在其它地方尝试是对的,我不是这个问题,pass~

点开了 CSDN 翻到后面看到这样一段话:

意思就是:你present的vc里面不能调用sdk的授权页面。因为sdk授权页面的出现方式就是present的,而iOS的框架机制限制了:如果在hierachy里已经有present的,则不能继续present,不管是用那个:目前被present的,还是目前present的父vc都不能再继续present一个新的vc

似乎我就是这个原因?在 Weibo SDK 的 issue 里翻到了这样一条记录 在keyWindow的rootVC上通过presentViewController跳转的视图中,调用授权接口提示Warning: Attempt to present <UINavigationController

可以知道 Weibo SDK 在历史上确实存在 A present 到 B,在 B 中调用接口会出现 Warning: Attempt to present on whose view is not in the window hierarchy!

不过早就已经修复了,我用的 SDK 版本应该没有这个问题。正当我准备给微博发 issue 时我突然怀疑起 CSDN 那个论调的正确性,既然如此 Weibo SDK 又如何能修复呢?想到这里动手写了个页面测试,发现根本就不存在这个问题~~

OK,那问题我已经猜到跟 Weibo SDK 无关了,肯定是我这边的问题。

###尝试,开始尝试

  1. [sheet bk_addButtonWithTitle:@”微博” handler:^{
    dispatch_async(dispatch_get_main_queue(), ^{

    //request weibo token here
    

    });
    }];//fail~~

  2. 不在 sheet 的回调中触发请求,在 viewDidLoad 中发起请求发现顺利的弹出了网页。至此已经把范围缩小了,不是 Weibo SDK 的锅,也不是 present 的锅。

接下来把注意力放到 BlocksKit 这个 handler 上。

又开始试错:

[sheet bk_addButtonWithTitle:@"微博" handler:^{
    UIViewController *vc = [UIViewController alloc] init];
    [self presentViewController:vc animated:YES completion:nil];
}];

发现完美的 present 一个黑色的页面出来。所以看来,锅不能只给 BlocksKit 背。

在 delegate

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 2) {
        //request weibo token here
    }
}

OK 问题解决,看了眼 Chrome 的历史记录我在 10:24 发起了这个 issue

总共耗时 68 分钟解决这个问题。

想来想去给谁发 issue 估计谁都不会理 sigh

Contents