【发布时间】:2014-01-09 09:26:40
【问题描述】:
我正在开发一个将接收推送通知的应用程序,当用户点击通知视图时,应用程序启动并且其中有 3 个 uitabs 并索引为 0,1 和 2。我需要的选项卡,当收到的通知是第二个索引是1.当标签1打开时,它将检测到如果此选项卡以推送通知响应,则@ 987654321将在URL。否则它将作为默认值。我正在发布我所有的代码,请帮助我。在此先感谢:)
这是我的didReceiveRemotenotification 方法,我正在创建一个整数并将其保存为一个标志来做出决定。
- AppDelegate.m
(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
int flg = 1;
[[NSUserDefaults standardUserDefaults] setInteger:flg forKey:@"flagvlu"];
[[NSUserDefaults standardUserDefaults] synchronize];
[[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotification" object:nil userInfo:userInfo];
}
然后它加载应用程序并打开第一个视图 Main.m - Main.m
(void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushNotificationReceived) name:@"pushNotification" object:nil];
}
-(void)pushNotificationReceived{
[self.tabBarController setSelectedIndex:1];
}
并将应用程序传递到下一个选项卡(Required.m),这是我需要的选项卡。我在其中有一个 uiwebview。
必填.m
- (void)viewDidLoad
{
[self doYourStuff];
[super viewDidLoad];
}
-(void)doYourStuff{
int flg = [[NSUserDefaults standardUserDefaults] integerForKey:@"flagvlu"];
if (flg == 1) {
[webPage reload];
[webPage loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];
flg = 0;
[[NSUserDefaults standardUserDefaults] setInteger:flg forKey:@"flagvlu"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
else if(flg == 0){
[webPage reload];
[webPage loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.yahoo.com"]]];
}
}
*现在的问题是应用收到通知,当用户点击视图时,它会启动应用并完美打开所需的选项卡,但不会在webview 中启动所需的URL。 :( 请帮助我是目标 c 开发的新手。
【问题讨论】:
-
哪个控制器正在加载选项卡索引以及您如何加载该控制器?
-
Required.m viewcontroller 是具有 uiwebview 的。我在应用程序启动时从 Main.m 加载它,因为 Required.m 是我的第二个选项卡(索引 1)。
标签: ios iphone objective-c xcode uiwebview