問題
我司的一個app因為這個原因被蘋果拒了捏境,要不然也不搞這個鬼東西!!借笙!
- 問題如下
Guideline 4.2.3 - Design - Minimum Functionality
We were required to install the WeChat app before we could log in via WeChat. Users should be able to log in with WeChat and access their accounts without having to install any additional apps.
Next Steps
If you would like to offer authentication through WeChat, please use a mechanism that allows users to log in with WeChat from within your app without first having to install an additional app.
We recommend implementing the Safari View Controller API to display web content within your app. The Safari View Controller allows the display of a URL and inspection of the certificate from an embedded browser in an app so that customers can verify the webpage URL and SSL certificate to confirm they are entering their sign in credentials into a legitimate page.
大體意思就是因為需要登錄微信才能使用我們的app俺泣,這是違反規(guī)則的疗认,最好無需安裝任何額外的應用就能訪問他們的賬戶巴拉巴拉~~
還給了個貼圖
解決
- 微信SDK1.7.8版本(我直接更新的最新的SDK)
不要相信文檔啊完残,文檔上說如果不安裝微信就沒法登錄!:崧谨设!
/*! @brief 發(fā)送Auth請求到微信,支持用戶沒安裝微信缎浇,等待微信返回onResp
*
* 函數調用后扎拣,會切換到微信的界面。第三方應用程序等待微信返回onResp素跺。微信在異步處理完成后一定會調用onResp二蓝。支持SendAuthReq類型。
* @param req 具體的發(fā)送請求指厌,在調用函數后刊愚,請自己釋放。
* @param viewController 當前界面對象仑乌。
* @param delegate WXApiDelegate對象百拓,用來接收微信觸發(fā)的消息。
* @return 成功返回YES晰甚,失敗返回NO衙传。
*/
+(BOOL) sendAuthReq:(SendAuthReq*)req viewController:(UIViewController*)viewController delegate:(id<WXApiDelegate>)delegate;
如果安裝了微信直接按照正常邏輯走,如果不是就調用sendLoginMsgToWweiXinWebPage這個方法
- sendLoginMsgToWweiXinWebPage 是我自己的一個方法厕九,如下
- (void) sendLoginMsgToWweiXinWebPage {
SendAuthReq* req =[[SendAuthReq alloc ] init];
req.scope = @"snsapi_userinfo";
req.state = @"pedometer_binding";
BOOL succeed = [WXApi sendAuthReq:req viewController:self delegate:self];
if (succeed) {
}
}
- 會出現手機登錄的網頁版蓖捶,填好手機號發(fā)送后會受到短信驗證,里面包含鏈接和信息扁远,點擊鏈接跳轉到app內部觸發(fā)登錄邏輯的回調
坑
-
點擊短信的鏈接回到app還是停留在發(fā)短信的頁面,或者停留在確認登錄的頁面俊鱼。
- (BOOL) application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
}
從短信點擊鏈接進入app的sourceApplication是字符串com.apple.MobileSMS
在這里我進行了字符串的校驗及處理,但是是沒有效果的畅买,回調的代理方法也沒有執(zhí)行并闲。
if ([sourceApplication isEqualToString:@"com.apple.MobileSMS"]) {
//微信網頁登錄
BOOL succeed = [WXApi handleOpenURL:url delegate:self];
return succeed;
}
下面這個方法也沒有調用
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
dispatch_async(dispatch_get_main_queue(), ^{
[WXApi handleOpenURL:url delegate:self];
});
return YES;
}
- 解決方法:使用下面的方法是正解, WXApiDelegate的回調方法 -(void) onResp:(BaseResp*)resp;也會被調用
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<NSString *,id> *)options {
dispatch_async(dispatch_get_main_queue(), ^{
[WXApi handleOpenURL:url delegate:self];
});
return YES;
}