2
我在開始屏幕上有6個按鈕的應用程序。我的問題是我想打開網頁點擊這些按鈕。我有這樣的代碼:在iOS應用程序內打開網頁
- (IBAction) accomodation: (id) sender
{
NSString *webPage1 = [NSString stringWithFormat:@"http://www.google.com"];
NSURL *url = [NSURL URLWithString:webPage1];
// [[UIApplication sharedApplication] openURL:url];
[self beginNavigationWith:2 andTitle:NSLocalizedStringFromTable(@"icn_txt_accomodations", LANGID, nil) andMap:nil andHtml:nil withIdTagsAroundMe: 1 withWeb:url];
}
這是用於初始化其中一個按鈕的方法。之後,我有方法:
- (void) beginNavigationWith: (int) navID andTitle:(NSString*) aTitle andMap:(NSString*) map andHtml:(NSString*) html withIdTagsAroundMe:(int)id_tags withWeb: (NSURL*) webPage
{
// DIRECT LINK
if (html != nil) {
if ([html hasPrefix:@"{ID}"]) {
NSError *error;
int res_id = [[html substringFromIndex:4] intValue];
NSLog(@"DIRECT ID From start>> %d", res_id);
NSFetchRequest* reqForRestaurant = [[NSFetchRequest alloc] init];
NSEntityDescription *resEntity2 = [NSEntityDescription entityForName:@"Restaurant" inManagedObjectContext:managedObjectContext];
[reqForRestaurant setEntity:resEntity2];
NSString *stringRes = [NSString stringWithFormat:@"res_id.intValue == %d", res_id];
NSPredicate *resPredicate2 = [NSPredicate predicateWithFormat:stringRes];
[reqForRestaurant setPredicate:resPredicate2];
NSArray *array3 = [managedObjectContext executeFetchRequest:reqForRestaurant error:&error];
//NSLog(@">>>> Gallery:%d", [managedObject.res_gallery intValue]);
if (array3 != nil) {
//NSLog(@"Restaurants count=%d", [array2 count]);
if ([array3 count] == 1) {
Restaurant *managedObjectRes = (Restaurant*) [array3 objectAtIndex:0];
RestaurantDetails *details = [[RestaurantDetails alloc] initWithStyle:UITableViewStylePlain];
details.managedObjectContext = self.managedObjectContext;
details.parentID = navID;
details.title = managedObjectRes.res_title;
[details initItemsWithData:managedObjectRes];
[self.navigationController pushViewController:details animated:YES];
}
}
return;
}
}
// STANDARD NAV o puro HTML
NavTableView *navTable = [[NavTableView alloc] initWithStyle:UITableViewStylePlain];
navTable.title = aTitle;
navTable.managedObjectContext = self.managedObjectContext;
navTable.selectQuery = [NSPredicate predicateWithFormat:@"nav_parent_id.intValue == %d", navID]; // parent id == 0 is ROOT
//added for use around me
navTable.id_tags_arroundme = id_tags;
[self.navigationController pushViewController:navTable animated:YES];
if (html != nil) [navTable addHtmlHeader:html];
if (map != nil) [navTable addActiveMap:map];
//WEB PAGE
if (webPage != nil) {
NSString *webPage1 = [NSString stringWithFormat:@"http://www.google.com"];
NSURL *url = [NSURL URLWithString:webPage1];
NSLog(@"url = %@",url);
[[UIApplication sharedApplication] openURL:url];
}
}
這種方式我設法打開網頁,但在薩法裏,我希望它在應用程序內。 有人可以給我一個方法來做到這一點。
謝謝。
以uiweb瀏覽並加載此網址即可查看 – Ron
在相關說明中,Apple允許這樣做嗎?在審查過程中。我有一個應用程序需求,我需要從一個與Instagram無關的應用程序中打開Instagram。蘋果是否有這個問題?使用UIWebView而不是在Safar中打開它? – Anil