問題
我司的一個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
*
* 函數(shù)調(diào)用后,會切換到微信的界面。第三方應用程序等待微信返回onResp。微信在異步處理完成后一定會調(diào)用onResp。支持SendAuthReq類型。
* @param req 具體的發(fā)送請求,在調(diào)用函數(shù)后,請自己釋放。
* @param viewController 當前界面對象。
* @param delegate WXApiDelegate對象,用來接收微信觸發(fā)的消息。
* @return 成功返回YES,失敗返回NO。
*/
+(BOOL) sendAuthReq:(SendAuthReq*)req viewController:(UIViewController*)viewController delegate:(id<WXApiDelegate>)delegate;
如果安裝了微信直接按照正常邏輯走,如果不是就調(diào)用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) {
}
}
- 會出現(xiàn)手機登錄的網(wǎng)頁版,填好手機號發(fā)送后會受到短信驗證,里面包含鏈接和信息,點擊鏈接跳轉(zhuǎn)到app內(nèi)部觸發(fā)登錄邏輯的回調(diào)
坑
-
點擊短信的鏈接回到app還是停留在發(fā)短信的頁面,或者停留在確認登錄的頁面。
點擊短信的鏈接回到app還是停留在發(fā)短信的頁面
- (BOOL) application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
}
從短信點擊鏈接進入app的sourceApplication是字符串com.apple.MobileSMS
在這里我進行了字符串的校驗及處理,但是是沒有效果的,回調(diào)的代理方法也沒有執(zhí)行。
if ([sourceApplication isEqualToString:@"com.apple.MobileSMS"]) {
//微信網(wǎng)頁登錄
BOOL succeed = [WXApi handleOpenURL:url delegate:self];
return succeed;
}
下面這個方法也沒有調(diào)用
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
dispatch_async(dispatch_get_main_queue(), ^{
[WXApi handleOpenURL:url delegate:self];
});
return YES;
}
- 解決方法:使用下面的方法是正解, WXApiDelegate的回調(diào)方法 -(void) onResp:(BaseResp*)resp;也會被調(diào)用
- (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;
}