在调整应用程序中定义的iOS URL方案不起作用? (越狱)

时间:2019-04-02 03:32:20

标签: ios jailbreak url-scheme theos tweak

与其他非越狱应用程序一样,我需要在用theos编写的调整应用程序中定义URL方案,但是它不起作用,有人有想法吗? 我已经建立了一个纯净的项目来对此进行测试,有人可以帮忙吗?非常感谢。 https://github.com/kentkrantz/testurlscheme

如何定义URL方案?

  1. 将此添加到Info.plist
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>com.yourcompany.testurlscheme</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>testus</string>
        </array>
    </dict>
</array>
  1. 将它们添加到AppDelegate.m
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    //    if (!url) {
    //        return NO;
    //    }
    NSLog(@">>>>>>>>>>>> 11111");
    NSLog(@"url recieved: %@", url);
    NSLog(@"query string: %@", [url query]);
    NSLog(@"host: %@", [url host]);
    NSLog(@"url path: %@", [url path]);
    NSDictionary *dict = [self parseQueryString:[url query]];
    NSLog(@"query dict: %@", dict);
    return YES;
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
    NSLog(@">>>>>>>>>>>> 22222");
    NSLog(@"url recieved: %@", url);
    NSLog(@"query string: %@", [url query]);
    NSLog(@"host: %@", [url host]);
    NSLog(@"url path: %@", [url path]);
    NSDictionary *dict = [self parseQueryString:[url query]];
    NSLog(@"query dict: %@", dict);
    return YES;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    NSLog(@">>>>>>>>>>>> 33333");
    NSLog(@"url recieved: %@", url);
    NSLog(@"query string: %@", [url query]);
    NSLog(@"host: %@", [url host]);
    NSLog(@"url path: %@", [url path]);
    NSDictionary *dict = [self parseQueryString:[url query]];
    NSLog(@"query dict: %@", dict);
    return YES;
}

- (NSDictionary *)parseQueryString:(NSString *)query
{
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:6];
    NSArray *pairs = [query componentsSeparatedByString:@"&"];

    for (NSString *pair in pairs) {
        NSArray *elements = [pair componentsSeparatedByString:@"="];
        NSString *key = [[elements objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSString *val = [[elements objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

        [dict setObject:val forKey:key];
    }
    return dict;
}

0 个答案:

没有答案