我有一個基本的webview應用程序正常工作,並從Parse.com接收基本的文本推送通知,但無法弄清楚如何讓它打開一個URL。iOS Webview App,如何在Webview中打開JSON Parse推送通知?
我想從Parse.com發送JSON推送通知是這樣的事情,並把它在我的WebView應用程序打開指定的URL:
編輯**我現在有新的問題是我」如果應用程序位於後臺或前臺,則無法在Web視圖中打開該網址。
目前,如果應用程序在後臺,並且點擊通知,它會將應用程序置於前臺,但不會重新加載新的URL。如果應用程序處於前臺,則會以通知的形式接收通知,而點擊「確定」時不會發生任何操作。
{
"alert": "Push title goes here",
"url": "http://www.google.com"
}
在我WebBrowserAppDelegate.m我有這樣的:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Parse setApplicationId:@"XXX"
clientKey:@"XXX"];
// Register for Push Notitications
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
// Override point for customization after application launch.
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
NSDictionary *notificationPayload = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
NSString *pushURL = [notificationPayload objectForKey:@"url"];
if (notification) {
NSDictionary *aDict=[NSDictionary dictionaryWithObject: pushURL forKey:@"urlToLoad"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"LoadRequestFromAppDel" object:Nil userInfo:aDict];
}
return YES;
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];
}
在我WebBrowserViewController.m我有這樣的:提前
- (void)viewDidLoad
{
[super viewDidLoad];
NSAssert(self.back, @"Unconnected IBOutlet 'back'");
NSAssert(self.forward, @"Unconnected IBOutlet 'forward'");
NSAssert(self.refresh, @"Unconnected IBOutlet 'refresh'");
NSAssert(self.stop, @"Unconnected IBOutlet 'stop'");
NSAssert(self.webView, @"Unconnected IBOutlet 'webView'");
self.webView.delegate = self;
self.webView.scalesPageToFit = YES;
NSURL* url = [NSURL URLWithString:@"http://www.mywebsite.com"];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
[self updateButtons];
}
- (void)LoadRequestFromAppDel: (NSNotification*)aNotif
{
NSString *aStrUrl=[[aNotif userInfo] objectForKey:@"urlToLoad"];
NSURL* pushurl = [NSURL URLWithString:aStrUrl];
NSURLRequest* requestObj = [NSURLRequest requestWithURL:pushurl];
[self.webView loadRequest:requestObj];
[self updateButtons];
}
感謝您的幫助!
你需要攔截來自解析的響應。我會告訴你一秒鐘。 – Loxx