iOS中获取其他APP安装状况是分析竞品的重要途径,推荐使用 系统的canopenUrl api,操作简单稳定;
首先需要拿到你想要获取app的Scheme,可以去知乎或其他网站去查阅,添加到你的infoPlist。也就是添加到白名单,然后获取列表;
具体代码如下:
info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>tim</string>
<string>mqqOpensdkSSoLogin</string>
...
</array>
</plist>
获取代码:我这里设置了扫描时间是一天一次
#import "BCYInstalledAppTrackManager.h"
#import "BCYFoundation.h"
#import "BCYTrackManager.h"
#import "Constants.h"
#import <UIKit/UIKit.h>
static NSString *const kBCYScanAppTimeKey = @"scan_app_time";
static NSUInteger const kBCYScanAppFrequencyHour = 24;
@implementation BCYInstalledAppTrackManager
+ (void)detectScheme {
//上一次扫描时间戳
NSDate *oldTime = (NSDate *)[USER_DEFAULTS objectForKey:kBCYScanAppTimeKey];
//当前时间戳
NSTimeInterval hours = -([oldTime timeIntervalSinceNow] / 3600);
if (oldTime == nil || hours > kBCYScanAppFrequencyHour) {
// app包名
NSArray *schemes = @[
@"iqiyi-acg", @"boodo", @"diyidanApp", @"uxinlive", @"kuaikan", @"comicreader", @"neteasecomic", @"LOFTER",
@"wbdm-app", @"acfun", @"bilibili", @"baozoumanhua", @"buka", @"u17app", @"dongman"
];
//扫描到的app
NSMutableString *scaned = [[NSMutableString alloc] init];
for (NSString *str in schemes) {
NSString *urlString = [str stringByAppendingString:@"://"];
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlString]]) {
NSString *trackString = [str stringByAppendingString:@"|"];
[scaned appendString:trackString];
}
}
// BDALOG_INFO(@"检测到竞品:%@",scaned);
NSDictionary *dic = @{@"app_package_list" : scaned};
//上报时候的时间
NSDate *now = [NSDate date];
[USER_DEFAULTS setObject:now forKey:kBCYScanAppTimeKey];
}
}
@end
网友评论