要在 iOS 应用程序中实现这一点,您可能需要下载这个 Apple 示例或(我更喜欢)这个方便的 github 项目
如果你选择第二种方式,你只需要像这样在启动时创建和配置可达性类实例
// disable automatic sending of statistics
[GAI sharedInstance].dispatchInterval = 0;
Reachability* reach = [Reachability reachabilityForLocalWiFi];
reach.reachableBlock = ^(Reachability *reach){
[GAI sharedInstance].dispatchInterval = 20;
// you also may send cached statistics right on WiFi appear
[[GAI sharedInstance] dispatch];
};
reach.unreachableBlock = ^(Reachability *reach) {
// disable automatic upload, this will force GAI to cache all hits
// until you call dispatch or set dispatchInterval
[GAI sharedInstance].dispatchInterval = 0;
};