用户界面 - 在 Web 视图中打开指定的 URL(iOS 推送)



在我的iOS应用程序中,我有一个UIWebView,那么我如何在UIWebView中打开指定的URL,并带有push notification

如果有人用notification打开应用程序,我想在UIWebView .

我可以将URL(在后台(与push notification绑定吗?

谢谢。

根据苹果...

如果应用正在运行并收到远程通知,则应用将 调用此方法以处理通知。您的实施 此方法应使用通知进行适当的课程 的行动。如果推送通知时应用未运行 到达,该方法启动应用程序并提供适当的 启动选项词典中的信息。应用不调用 此方法用于处理该推送通知。相反,您的 application:willFinishLaunchingWithOptions: application:didFinishLaunchingWithOptions:方法需要获得 推送通知有效负载数据并做出适当响应。

因此,有三种可能的情况:

1(应用程序在前台:您将拥有完全控制权,只需实施didReceiveNotification并做任何您想做的事情。

2( 应用正在运行,但在后台运行:在用户使用收到的通知实际打开应用之前,不会触发操作。

3(应用程序未运行:在这种情况下,您应该实现didFinishLaunchingWithOptions以获取其他信息并执行任务。

因此,代码应如下所示didFinishLaunchingWithOptions

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSDictionary *userInfo = [launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
    NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
    if(apsInfo) {
        // Get the URL or any other data
    }
}

这是didReceiveNotification的近似值

/**
 * Remote Notification Received while application was open.
 */
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    #if !TARGET_IPHONE_SIMULATOR
    UIApplicationState state = [application applicationState];
    if (state == UIApplicationStateActive)
    {
        NSString *message = nil;
        id aps = [userInfo objectForKey:@"aps"];
        if ([aps isKindOfClass:[NSDictionary class]]) {
            message = [aps objectForKey:@"alert"];
        }
        if (message) {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Notificación"
                                                                message:message
                                                               delegate:self
                                                cancelButtonTitle:@"Aceptar"
                                                      otherButtonTitles:nil, nil];
            [alertView show];
        }
    }
    // Aditional data
    NSString *url = [userInfo objectForKey:@"url"];
    NSLog(@"Received Push URL: %@", url);
    if(url!=nil)
    {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
    }
    NSLog(@"remote notification: %@",[userInfo description]);
    NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
    NSString *alert = [apsInfo objectForKey:@"alert"];
    NSLog(@"Received Push Alert: %@", alert);
    NSString *sound = [apsInfo objectForKey:@"sound"];
    NSLog(@"Received Push Sound: %@", sound);
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
    NSString *badge = [apsInfo objectForKey:@"badge"];
    NSLog(@"Received Push Badge: %@", badge);
    application.applicationIconBadgeNumber = [[apsInfo objectForKey:@"badge"] integerValue];
    #endif
}

相关内容

  • 没有找到相关文章

最新更新