ios6 - How to use OpenURL to pass in a URL and then performSegue while retaining the URL? -
i trying open file (csv) e-mail app, parse , import data (students) course. have parsed , imported data via file in itunes , dropbox, struggling on getting file passed in e-mail.
specifically, flow looks this: open e-mail > select file open app > app launches , reads file first view controller ... here stuck:
i modal view popup user can select course want imported data (students) go into.
the app delegate tells first view controller handle url:
// first view controller -(void) handleopenurl:(nsurl *)url { _importedfileurl=url; // if nslog this, can see file makes in [self performseguewithidentifier:@"select course import" sender:self]; // ***fail ***// }
the storyboard wired correctly, because if use nsnotification can modal view appear (but lose value url). seems though view hasn't gotten chance appear , therefore can't handle segue.
any suggestions on how can modal view appear , retain _importedfileurl?
solved: using nsnotification center, suspected :d
in appdelegate(.m) added following routine within openurl
- (bool)application:(uiapplication *)application openurl:(nsurl *)url sourceapplication:(nsstring *)sourceapplication annotation:(id)annotation { ... other code handle dropbox imported urls // check see if file has been sent on via app, e-mail if (url != nil && [url isfileurl]) { mainviewcontroller *firstviewcontroller = [[mainviewcontroller alloc]init]; [firstviewcontroller handleopenurl:url]; nsurl *filefromemail=url; // add url dictionary item, can open nsnotificationcenter nsdictionary *fileinfo=[nsdictionary dictionarywithobject:filefromemail forkey:@"filefromemail"]; // add notification named "seguelistener" , pass on dictionary object [[nsnotificationcenter defaultcenter] postnotificationname:@"seguelistener" object:nil userinfo:fileinfo]; return yes; } }
and in mainviewcontroller(.m) in viewdidload, added added nsnotification observer:
- (void)viewdidload { [super viewdidload]; ... // if notification named "seguelistener" sent out, perform method: seguetoimportfile [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(seguetoimportfile:) name:@"seguelistener" object:nil]; }
and added handleopenurl method:
-(void) handleopenurl:(nsurl *)url { // capture url , store _importedfileurl (nsurl) _importedfileurl=url; }
and seguetoimportfile method:
-(void)seguetoimportfile:(nsnotification *)notification { nsdictionary *file=[notification userinfo]; // dictionary object userinfo _importedfileurl=[file objectforkey:@"filefromemail"]; [self performseguewithidentifier:@"select course import" sender:self]; }
and segue send on _importedfileurl new tableviewcontroller lists courses:
-(void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { uinavigationcontroller *navigationcontroller=segue.destinationviewcontroller; selectcoursetableviewcontroller *selectcoursetableviewcontroller=[[navigationcontroller viewcontrollers]objectatindex:0]; selectcoursetableviewcontroller.seguefrom=@"email import"; // storyboard selectcoursetableviewcontroller.importedfile = _importedfileurl; }
Comments
Post a Comment