Ios5 使用Facebook;iOS本机深度链接“;和基于iOS 5情节提要/segue的应用程序的openURL?
我有一个支持Facebook的iOS 5应用程序,它使用故事板和基于segue的导航,对如何实现“iOS本机深度链接”感到困惑。上的示例代码只显示了一个Ios5 使用Facebook;iOS本机深度链接“;和基于iOS 5情节提要/segue的应用程序的openURL?,ios5,uistoryboard,facebook-ios-sdk,uistoryboardsegue,Ios5,Uistoryboard,Facebook Ios Sdk,Uistoryboardsegue,我有一个支持Facebook的iOS 5应用程序,它使用故事板和基于segue的导航,对如何实现“iOS本机深度链接”感到困惑。上的示例代码只显示了一个UIAlertView,但我正在尝试启动两个连续的顺序操作 为了解决这个问题,我将应用程序简化为三个视图控制器:MYCategoryTableViewController、MYItemsTableViewController和MYItemViewController。在正常流程中,应用程序打开到MYCategoryTableViewControl
UIAlertView
,但我正在尝试启动两个连续的顺序操作
为了解决这个问题,我将应用程序简化为三个视图控制器:MYCategoryTableViewController
、MYItemsTableViewController
和MYItemViewController
。在正常流程中,应用程序打开到MYCategoryTableViewController,其中显示类别表。当用户选择一个类别时,会出现一个到MYItemsTableViewController
的序列,该序列显示所选类别的项目表。最后,当选择一个项目时,会出现一个到MYItemViewController
的序列,显示项目详细视图
来自MYCategoryTableViewController的prepareForSegue
在目标视图控制器上设置表示该类别的属性:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"ITEMS_SEGUE"]) {
MYItemsTableViewController *vc = [segue destinationViewController];
MYCategory *mycategory = [self.fetchedResultsController objectAtIndexPath:[self.tableView indexPathForSelectedRow]];
vc.mycategory = mycategory;
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"ITEM_SEGUE"]) {
MYItemViewController *vc = [segue destinationViewController];
MYItem *myitem = [self.fetchedResultsController objectAtIndexPath:[self.tableView indexPathForSelectedRow]];
vc.myitem = myitem;
}
}
来自MYItemsTableViewController的prepareForSegue
在目标视图控制器上设置表示该类别的属性:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"ITEMS_SEGUE"]) {
MYItemsTableViewController *vc = [segue destinationViewController];
MYCategory *mycategory = [self.fetchedResultsController objectAtIndexPath:[self.tableView indexPathForSelectedRow]];
vc.mycategory = mycategory;
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"ITEM_SEGUE"]) {
MYItemViewController *vc = [segue destinationViewController];
MYItem *myitem = [self.fetchedResultsController objectAtIndexPath:[self.tableView indexPathForSelectedRow]];
vc.myitem = myitem;
}
}
问题:我知道我需要在应用程序中实现一些东西:openURL
,但不确定下一步要做什么。假设传入URL提供了用于查找MYCategory
和MYItem
对象的标识符。我找到了performsguewithidentifier
,但不确定它如何与prepareforsgue
交互,以及如何在目标视图控制器上设置模型对象
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
// get "target_url" from incoming url
// and parse out MYCategory and MYItem identifiers
// something like this???
[self.window makeKeyAndVisible];
[self.window.rootViewController performSegueWithIdentifier:@"ITEM_SEGUE" sender:self];
return [facebook handleOpenURL:url];
}
更新:给了我一个想法。也许我只是从
应用程序:openURL:
中保存url,然后让MYCategoryTableViewController
自然加载。然后在视图出现期间
,调用表格视图选择Rowatindexpath
,然后使用标识符执行GUE
以转换到MyItemStableViewer控制器
。在MYItemsTableViewController
中重复相同的模式,但在调用performsguewithidentifier
之前清除url。以下是我的工作。在MYAppDelegate
中,我捕获了一个表示深度链接id的字符串
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
NSString *deepLinkId;
// more code that parses url
// only deep link if MYCategoryTableViewController is active controller
UIViewController *rootContoller = self.window.rootViewController;
if ([rootContoller isKindOfClass:[UINavigationController class]]) {
UINavigationController *navController = (UINavigationController *)rootContoller;
if ([navController.topViewController isKindOfClass:[MYCategoryTableViewController class]]) {
self.deepLinkId = deepLinkId;
}
}
}
然后,当MYCategoryTableViewController
加载时,调用selectRowAtIndexPath
,然后调用PerformsgueWithIdentifier
- (void)processDeepLink {
if (_appDelegate.deepLinkId) {
MYItem *myitem = [MYItem lookupById:_appDelegate.deepLinkId inManagedObjectContext:_appDelegate.dataDocument.managedObjectContext];
if (myitem) {
NSIndexPath *indexPath = [self.fetchedResultsController indexPathForObject:myitem.mycategory];
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];
[self performSegueWithIdentifier:@"ITEMS_SEGUE" sender:self];
}
}
}
当MYItemViewController
加载时,会出现类似的流
if (_appDelegate.deepLinkId) {
MYItem *plate = [MYItem lookupById:_appDelegate.deepLinkId inManagedObjectContext:_appDelegate.dataDocument.managedObjectContext];
NSIndexPath *indexPath = [self.fetchedResultsController indexPathForObject:plate];
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];
_appDelegate.deepLinkId = nil;
[self performSegueWithIdentifier:@"ITEM_SEGUE" sender:self];
}
当应用程序已经打开时,我还必须观察用例的uiapplicationidbecomeactivityfication
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(processDeepLink)
name:UIApplicationDidBecomeActiveNotification
object:nil];
这是我的工作。在
MYAppDelegate
中,我捕获了一个表示深度链接id的字符串
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
NSString *deepLinkId;
// more code that parses url
// only deep link if MYCategoryTableViewController is active controller
UIViewController *rootContoller = self.window.rootViewController;
if ([rootContoller isKindOfClass:[UINavigationController class]]) {
UINavigationController *navController = (UINavigationController *)rootContoller;
if ([navController.topViewController isKindOfClass:[MYCategoryTableViewController class]]) {
self.deepLinkId = deepLinkId;
}
}
}
然后,当MYCategoryTableViewController
加载时,调用selectRowAtIndexPath
,然后调用PerformsgueWithIdentifier
- (void)processDeepLink {
if (_appDelegate.deepLinkId) {
MYItem *myitem = [MYItem lookupById:_appDelegate.deepLinkId inManagedObjectContext:_appDelegate.dataDocument.managedObjectContext];
if (myitem) {
NSIndexPath *indexPath = [self.fetchedResultsController indexPathForObject:myitem.mycategory];
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];
[self performSegueWithIdentifier:@"ITEMS_SEGUE" sender:self];
}
}
}
当MYItemViewController
加载时,会出现类似的流
if (_appDelegate.deepLinkId) {
MYItem *plate = [MYItem lookupById:_appDelegate.deepLinkId inManagedObjectContext:_appDelegate.dataDocument.managedObjectContext];
NSIndexPath *indexPath = [self.fetchedResultsController indexPathForObject:plate];
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];
_appDelegate.deepLinkId = nil;
[self performSegueWithIdentifier:@"ITEM_SEGUE" sender:self];
}
当应用程序已经打开时,我还必须观察用例的uiapplicationidbecomeactivityfication
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(processDeepLink)
name:UIApplicationDidBecomeActiveNotification
object:nil];