iosobjective-ciphoneurbanairship.com

Urban Airship iOS show message body on UIWebView


anyone has doing something like this on iOS?, this is the challenge, in my app i already configure UrbanAirship methods and have access to the user´s current messages as an UAInboxMessage array and display them on a table where the cell title its the message title, ok... now, looking into each object properties they have an messageURL and messageBodyURL, when i request those url´s Urban ask for credentials, ok, when i touch on a row on my tableView, i send the message to a DetailViewController as a property, in that view i have a UIWebView and what i want is show the message Rich content, which is the html previously configured in Urban Console, in the UIWebView in my DetailViewController, so i was trying to get it via UAWebViewCallData sending the url, the webview and the message but no luck...

[UAWebViewCallData callDataForURL:message.messageBodyURL webView:_webView message:message];

No work.

I tried to set UA custom delegates to my webview like UAWebViewDelegate for getting the info, and agail i failed, those delegates never were called.

And manual display like the doc https://docs.urbanairship.com/platform/ios/#display

and again not working, then a friend found on Android there is a UAWebView custom class, where he can extend its webview from that, and just writing this, the message body was showed

extendedWebView.loadRichPushMessage(this.message);

try to find on iOS something similar but no luck.

please help!!


Solution

  • Accessing the Message Center HTML content requires a unique set of credentials. They should be retrieved via the Urban Airship SDK utility methods and added to your request. For example:

    NSMutableURLRequest *requestObj = [NSMutableURLRequest 
    requestWithURL:self.message.messageBodyURL];
    requestObj.timeoutInterval = 10;
    
    NSString *auth = [UAUtils appAuthHeaderString];
    [requestObj setValue:auth forHTTPHeaderField:@"Authorization"];
    [self.webView loadRequest:requestObj];
    

    You can also take a look at how the webview is configured and loaded in the default Message Center that Urban Airship provides here: https://github.com/urbanairship/ios-library/blob/master/AirshipKit/AirshipKit/ios/UADefaultMessageCenterMessageViewController.m

    swift4:

        let request = NSMutableURLRequest(url: url)
        request.timeoutInterval = 10;
    
        let auth = UAUtils.appAuthHeaderString()
        request.setValue(auth, forHTTPHeaderField: "Authorization")
        ....