iOS:检测我的 SDK 是否安装在设备上的其他应用程序上 [英] iOS: Detect whether my SDK is installed on another apps on the device

查看:46
本文介绍了iOS:检测我的 SDK 是否安装在设备上的其他应用程序上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为移动设备开发基于位置的问答 SDK.

I am developing a location based Q&A SDK for mobile devices.

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

When a question is asked about a specific location, the server side targets the most relevant user and sends the question to that user. If the user fails to answer, the question is sent to the second best user, and so on.

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

The problem is that my SDK might be installed on more than one application on the device, meaning that the user can get a question more than once.

有没有办法检测我的 SDK 是否安装在多个应用程序上?我认为将 UDID 发送到服务器可能会起作用,但是 iOS UDID 因应用程序而异.

Is there a way to detect whether my SDK is installed on more than one app? I thought that sending the UDID to the server might work, but iOS UDIDs differ between applications.

推荐答案

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

You can use UIPasteboard to share data between applications on the device.

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

The UIPasteboard class enables an app to share data within the app and with another app. To share data with any other app, you can use system-wide pasteboards; to share data with another app that has the same team ID as your app, you can use app-specific pasteboards.

在您的 SDK 中,执行以下操作:

In your SDK, do something like this:

@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

这篇关于iOS:检测我的 SDK 是否安装在设备上的其他应用程序上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆