【发布时间】:2013-11-15 22:48:32
【问题描述】:
当用户选择使用自定义 URL 打开附件时,我希望能够从电子邮件应用调用我的应用。貌似IOS确实识别注册了,但是还是没有调用应用代理打开URL。
我已将我的应用注册为支持自定义 URL,方法是将其添加到 info.plist;
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.plain-text</string>
<string>public.text</string>
</array>
<key>UTTypeDescription</key>
<string>TecNotes Data File</string>
<key>UTTypeIdentifier</key>
<string>com.bringardner.textext</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<string>testext</string>
<key>public.mime-type</key>
<string>application/vnd.testext+xml</string>
</dict>
</dict>
</array>
这是应用程序委托的代码;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
if( launchOptions == nil) {
NSLog(@"nil options");
} else {
NSLog(@"Have options");
NSObject *obj = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
NSLog(@"url? %@",obj);
}
return YES;
}
-(BOOL) application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
NSLog(@"handle %@",url);
return YES;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
NSLog(@"open %@",url);
return YES;
}
-(BOOL) application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"willFinishLaunchingWithOptions ");
return YES;
}
在 info.plist 添加条目之前,我从电子邮件应用程序收到以下消息; 将条目添加到 info.plist 后,电子邮件应用程序会打开一个空白页面,但不会调用任何应用程序委托方法。
我见过几个类似的问题,但我尝试过的都没有解决这个问题。
【问题讨论】: