<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AppsFlyer 归档 - 初晴神社</title>
	<atom:link href="https://vki.cc/tag/appsflyer/feed/" rel="self" type="application/rss+xml" />
	<link>https://vki.cc/tag/appsflyer/</link>
	<description>白露的博客</description>
	<lastBuildDate>Thu, 10 Jun 2021 06:19:05 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>

<image>
	<url>https://cdn.vki.cc/wp-content/uploads/2018/03/cropped-icemaplen-1-32x32.png</url>
	<title>AppsFlyer 归档 - 初晴神社</title>
	<link>https://vki.cc/tag/appsflyer/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>记一次由接入AppsFlyer导致海外iOS无法登录的问题</title>
		<link>https://vki.cc/greattruth/experience/861/</link>
					<comments>https://vki.cc/greattruth/experience/861/#respond</comments>
		
		<dc:creator><![CDATA[白露]]></dc:creator>
		<pubDate>Thu, 10 Jun 2021 06:11:42 +0000</pubDate>
				<category><![CDATA[咸鱼心得]]></category>
		<category><![CDATA[朝闻道]]></category>
		<category><![CDATA[AppsFlyer]]></category>
		<category><![CDATA[SDK]]></category>
		<guid isPermaLink="false">https://vki.cc/?p=861</guid>

					<description><![CDATA[<p>项目临近发布前测试发现的，具体表现为在iOS设备上，使用TapTap登录，输入完账号密码后点击登录游戏无反应，再次点击需要再次登录。</p>
<p><a href="https://vki.cc/greattruth/experience/861/">记一次由接入AppsFlyer导致海外iOS无法登录的问题</a>最先出现在<a href="https://vki.cc">初晴神社</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading" id="id-记一次由接入AppsFlyerSDK导致海外iOS无法登录的问题-Bug表现"><span id="bug%e8%a1%a8%e7%8e%b0">Bug表现</span></h3>



<p class="wp-block-paragraph">服务器：海外服</p>



<p class="wp-block-paragraph">平台：iOS</p>



<p class="wp-block-paragraph">项目临近发布前测试发现的，具体表现为在iOS设备上，使用TapTap登录，输入完账号密码后点击登录游戏无反应，再次点击需要再次登录。</p>



<h3 class="wp-block-heading" id="id-记一次由接入AppsFlyerSDK导致海外iOS无法登录的问题-排查过程"><span id="%e6%8e%92%e6%9f%a5%e8%bf%87%e7%a8%8b">排查过程</span></h3>



<p class="wp-block-paragraph">查找过程中发现成功拉起TapTap登录没有异常，但是在TapTap上点击登录后游戏<strong>没有收到任何回调</strong>。</p>



<p class="wp-block-paragraph">正常情况下，<strong>点击登录之后SDK会调用对应的回调方法</strong>，包括：</p>



<p class="wp-block-paragraph">登录成功（OnLoginSuccess）</p>



<p class="wp-block-paragraph">登录失败（OnLoginError）</p>



<p class="wp-block-paragraph">登录取消（OnLoginCancel）</p>



<p class="wp-block-paragraph">最终在TapSDK的同学帮助下定位了问题，本应由TapSDK传给客户端的消息被AppsFlyer拦截了。。</p>



<p class="wp-block-paragraph">相关AppsFlyer代码如下：</p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">//  AppsFlyerAppController.mm
//  Unity-iPhone
//
//  Created by Jonathan Wesfield on 30/07/2019.
//
 
#import &lt;Foundation/Foundation.h>
#import "UnityAppController.h"
#import "AppDelegateListener.h"
#import "AppsFlyeriOSWrapper.h"
#if __has_include(&lt;AppsFlyerLib/AppsFlyerLib.h>)
#import &lt;AppsFlyerLib/AppsFlyerLib.h>
#else
#import "AppsFlyerLib.h"
#endif
#import &lt;objc/message.h>
 
/**
 Note if you would like to use method swizzeling see AppsFlyer+AppController.m
 If you are using swizzeling then comment out the method that is being swizzeled in AppsFlyerAppController.mm
 Only use swizzeling if there are conflicts with other plugins that needs to be resolved.
*/
 
 
@interface AppsFlyerAppController : UnityAppController &lt;AppDelegateListener>
{
    BOOL didEnteredBackGround;
}
@end
 
@implementation AppsFlyerAppController
 
- (instancetype)init
{
    self = [super init];
    if (self) {
         
        id swizzleFlag = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppsFlyerShouldSwizzle"];
        BOOL shouldSwizzle = swizzleFlag ? [swizzleFlag boolValue] : NO;
         
        if(!shouldSwizzle){
            UnityRegisterAppDelegateListener(self);
        }
    }
    return self;
}
 
- (void)didFinishLaunching:(NSNotification*)notification {
    NSLog(@"got didFinishLaunching = %@",notification.userInfo);
 
 
    if (_AppsFlyerdelegate == nil) {
        _AppsFlyerdelegate = [[AppsFlyeriOSWarpper alloc] init];
    }
    [[AppsFlyerLib shared] setDelegate:_AppsFlyerdelegate];
 
    if (notification.userInfo[@"url"]) {
        [self onOpenURL:notification];
    }
}
 
-(void)didBecomeActive:(NSNotification*)notification {
    NSLog(@"got didBecomeActive(out) = %@", notification.userInfo);
    if (didEnteredBackGround == YES &amp;&amp; AppsFlyeriOSWarpper.didCallStart == YES) {
        [[AppsFlyerLib shared] start];
        didEnteredBackGround = NO;
    }
}
 
- (void)didEnterBackground:(NSNotification*)notification {
    NSLog(@"got didEnterBackground = %@", notification.userInfo);
    didEnteredBackGround = YES;
}
 
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler {
    [super application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
    [[AppsFlyerAttribution shared] continueUserActivity:userActivity restorationHandler:restorationHandler];
    return YES;
}
 
-(BOOL) application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *)options {
    NSLog(@"got openUrl: %@",url);
    [super application:application openURL:url options:options];
    [[AppsFlyerAttribution shared] handleOpenUrl:url options:options];
    return NO;
}
 
- (void)onOpenURL:(NSNotification*)notification {
    NSLog(@"got onOpenURL = %@", notification.userInfo);
    NSURL *url = notification.userInfo[@"url"];
    NSString *sourceApplication = notification.userInfo[@"sourceApplication"];
     
    if (sourceApplication == nil) {
        sourceApplication = @"";
    }
     
    if (url != nil) {
        [[AppsFlyerAttribution shared] handleOpenUrl:url sourceApplication:sourceApplication annotation:nil];
    }
     
}
 
- (void)didReceiveRemoteNotification:(NSNotification*)notification {
    NSLog(@"got didReceiveRemoteNotification = %@", notification.userInfo);
    [[AppsFlyerLib shared] handlePushNotification:notification.userInfo];
}
 
@end
 
IMPL_APP_CONTROLLER_SUBCLASS(AppsFlyerAppController)
 
 
/**
Note if you would not like to use IMPL_APP_CONTROLLER_SUBCLASS you can replace it with the code below.
 &lt;code>
 +(void)load
 {
 [AppsFlyerAppController plugin];
 }
  
 // Singleton accessor.
 + (AppsFlyerAppController *)plugin
 {
 static AppsFlyerAppController *sharedInstance = nil;
 static dispatch_once_t onceToken;
  
 dispatch_once(&amp;onceToken, ^{
  
 sharedInstance = [[AppsFlyerAppController alloc] init];
 });
  
 return sharedInstance;
 }
&lt;/code>
 **/</pre>



<p class="wp-block-paragraph">首先TapTap的跳转登录是通过修改UnityAppController中的openURL等相关函数实现的；</p>



<p class="wp-block-paragraph">而该SDK通过&nbsp;IMPL_APP_CONTROLLER_SUBCLASS(AppsFlyerAppController) 将自己的AppController文件替换掉了原本的UnityAppController，导致原先TapTap SDK的代码没有生效，以至于无法接收到登录回调，最后无法登录。。</p>



<h3 class="wp-block-heading" id="id-记一次由接入AppsFlyerSDK导致海外iOS无法登录的问题-解决方法"><span id="%e8%a7%a3%e5%86%b3%e6%96%b9%e6%b3%95">解决方法</span></h3>



<ol class="wp-block-list"><li>删除AppsFlyer；</li><li>在AppsFlyer的AppController中调用原UnityAppController的函数；</li></ol>



<p class="wp-block-paragraph">这两种方法都可以，国内版不需要AppsFlyer所以可以删掉。但是海外版还是需要该SDK的。</p>



<p class="wp-block-paragraph">考虑到该AppController类继承自UnityAppController，最终采用了方法2，以openURL函数为例：</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">-(BOOL) application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *)options {
NSLog(@"got openUrl: %@",url);
[super application:application openURL:url options:options];
[[AppsFlyerAttribution shared] handleOpenUrl:url options:options];
return NO;
}</pre>



<p class="wp-block-paragraph">增加&nbsp;[super application:application openURL:url options:options];&nbsp;语句，重新调用了父类UnityAppController的openURL函数，使得游戏可以正常接受来自TapSDK的信息，成功登录。</p>



<p class="wp-block-paragraph">同时，假如以后不需要该SDK了，可以直接删除而不用修改代码（删除之后会默认使用原有的UnityAppController）。</p>



<h3 class="wp-block-heading" id="id-记一次由接入AppsFlyerSDK导致海外iOS无法登录的问题-反思"><span id="%e5%8f%8d%e6%80%9d">反思</span></h3>



<p class="wp-block-paragraph">我的锅。。其实以我的计划来说，AppsFlyer已经接入游戏，但还没有经过测试，这次出版本来不及，所以我加了开关给关掉了。</p>



<p class="wp-block-paragraph">可是万万没想到AppsFlyer SDK还有替换AppController这一手，我接了那么多SDK第一次见，还是我太naive了。。。</p>



<p class="wp-block-paragraph">辛苦几位同事大半夜还在找bug，这里说声抱歉 Orz<a href="https://confluence.xindong.com/pages/viewpage.action?pageId=193701575"></a></p>
<p><a href="https://vki.cc/greattruth/experience/861/">记一次由接入AppsFlyer导致海外iOS无法登录的问题</a>最先出现在<a href="https://vki.cc">初晴神社</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://vki.cc/greattruth/experience/861/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
