參見:iPhone App Programming Guide
這是你的第二個應用程序必須做什麼,以處理從第一公開徵集:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if ([[url scheme] isEqualToString:@"todolist"]) {
ToDoItem *item = [[ToDoItem alloc] init];
NSString *taskName = [url query];
if (!taskName || ![self isValidTaskString:taskName]) { // must have a task name
[item release];
return NO;
}
taskName = [taskName stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
item.toDoTask = taskName;
NSString *dateString = [url fragment];
if (!dateString || [dateString isEqualToString:@"today"]) {
item.dateDue = [NSDate date];
} else {
if (![self isValidDateString:dateString]) {
[item release];
return NO;
}
// format: yyyymmddhhmm (24-hour clock)
NSString *curStr = [dateString substringWithRange:NSMakeRange(0, 4)];
NSInteger yeardigit = [curStr integerValue];
curStr = [dateString substringWithRange:NSMakeRange(4, 2)];
NSInteger monthdigit = [curStr integerValue];
curStr = [dateString substringWithRange:NSMakeRange(6, 2)];
NSInteger daydigit = [curStr integerValue];
curStr = [dateString substringWithRange:NSMakeRange(8, 2)];
NSInteger hourdigit = [curStr integerValue];
curStr = [dateString substringWithRange:NSMakeRange(10, 2)];
NSInteger minutedigit = [curStr integerValue];
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setYear:yeardigit];
[dateComps setMonth:monthdigit];
[dateComps setDay:daydigit];
[dateComps setHour:hourdigit];
[dateComps setMinute:minutedigit];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDate *itemDate = [calendar dateFromComponents:dateComps];
if (!itemDate) {
[dateComps release];
[item release];
return NO;
}
item.dateDue = itemDate;
[dateComps release];
}
[(NSMutableArray *)self.list addObject:item];
[item release];
return YES;
}
return NO;
}
而且第一個應用程序打開它就像這樣:
NSURL *myURL = [NSURL URLWithString:@"todolist://www.acme.com?Quarterly%20Report#200806231300"];
[[UIApplication sharedApplication] openURL:myURL];
這是最重要的故事。被調用的應用程序還需要在其info.plist中註冊URL協議(在您的示例中,使用「todolist」),這裏解釋:http://www.mobileorchard.com/apple-approved-iphone-inter-process-通訊/ – 2009-11-12 05:43:01
非常感謝... 嘿,但todolist存儲在我們的本地磁盤目錄中的權利?然後Ÿ將其稱爲://www.acme.com?Quarterly%20Report#200806231300「]; 例如,如果在路徑中保存我的todolist應用:// macintosh HD/Users/home/todolist我可以寫上面的代碼 NSURL URLWithString:@ 「todolist的://://的Macintosh HD /用戶/主頁/ todolist的」]; PLZ電話我是用來調用我的todolist的應用程序的正確方法? – suse 2009-11-12 05:53:54
喜Mahboudz, 我應該在哪裏註冊URLtype ...在todolist應用程序或在調用todolist的應用程序中? – suse 2009-11-12 06:21:01