iOS:检测我的SDK是否安装在设备上的其他应用上

Ada*_*tan 5 sdk udid ios

我正在为移动设备开发基于位置的Q&A SDK.

当询问有关特定位置的问题时,服务器端将针对最相关的用户并将问题发送给该用户.如果用户未能回答,则将问题发送给第二个最佳用户,依此类推.

问题是我的SDK可能安装在设备上的多个应用程序中,这意味着用户可以多次获得一个问题.

有没有办法检测我的SDK是否安装在多个应用程序上?我认为将UDID发送到服务器可能有效,但iOS UDID在应用程序之间有所不同.

art*_*dev 5

您可以使用UIPasteboard在设备上的应用程序之间共享数据.

UIPasteboard类使应用程序能够在应用程序内与其他应用程序共享数据.要与任何其他应用程序共享数据,您可以使用系统范围的粘贴板; 要与具有与您的应用具有相同团队ID的其他应用共享数据,您可以使用特定于应用的粘贴板.

在SDK中,执行以下操作:

@interface SDKDetector : NSObject

@end

@implementation SDKDetector

+ (void)load
{
    int numberOfApps = (int)[self numberOfAppsInDeviceUsingSDK];
    NSLog(@"Number of apps using sdk:%d", numberOfApps);
}

+ (NSInteger)numberOfAppsInDeviceUsingSDK
{
    static NSString *pasteboardType = @"mySDKPasteboardUniqueKey";

    NSData *value = [[UIPasteboard generalPasteboard] valueForPasteboardType:pasteboardType];
    NSMutableArray *storedData = [[NSKeyedUnarchiver unarchiveObjectWithData:value] mutableCopy];

    if (!storedData) {
        storedData = [NSMutableArray new];
    }

    NSString *bundleId = [[NSBundle mainBundle] bundleIdentifier];
    if (![storedData containsObject:bundleId]) {
        [storedData addObject:[[NSBundle mainBundle] bundleIdentifier]];
    }

    value = [NSKeyedArchiver archivedDataWithRootObject:storedData];
    [[UIPasteboard generalPasteboard] setData:value forPasteboardType:pasteboardType];

    return [storedData count];
}

@end
Run Code Online (Sandbox Code Playgroud)