IOS实现Custom Protocol

在IOS中,实现Custom Protocol,需要以下两步:

1、修改Info.plist文件,增加以下内容:

    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLName</key>
            <string>com.neohope.custom.protocol.test</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>myproto</string>
            </array>
        </dict>
    </array>

2、在AppDelegate.m中,增加以下内容:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    if(url!=nil)
    {
        NSString *path = url.absoluteString;
        //do your job here
    }
    return YES;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*