Need a working fb example: as in a UIWebView with edge.create / remove event firing

summary: edge.create stopped the inline HTML from running inside the UIWebView (and I didn’t change anything in the code) - any ideas how I can return it?


I have an iOS application that has a UIWebView with a Facebook Like button. enter image description here

The user logs into Facebook BEFORE this dialog box, so the logon logic does not occur.

I can click as / unlike - and it works fine, but it closed the dialog and it broke a few days ago. Closing the dialog was achieved by subscribing to edge.create / edge.remove events.

Here is my HTML page:

<html>
    <head>
        <style type='text/css'>
            * { -webkit-touch-callout: none; -webkit-user-select: none; }
            body { margin:0px; }
            .fb_edge_comment_widget { display: none !important; }
        </style>
    </head>
    <body>                   
        <div id='fb-root'></div>
        <script src='http://connect.facebook.net/en_US/all.js#xfbml=1'></script>
        <script>
            function forwardEvent(name) {
                var iframe = document.createElement('iframe');
                iframe.setAttribute('src', 'event:' + name);
                document.documentElement.appendChild(iframe);
                iframe.parentNode.removeChild(iframe);  
            };
            function beginForwardingEvent(name) {
                FB.Event.subscribe(name, function(r) { forwardEvent(name); });
            };
            function beginForwardingEvents(names) {
                for (var i = 0; i < names.length; i++) {
                    beginForwardingEvent(names[i]);
                }
            };
            beginForwardingEvents(['edge.create', 'edge.remove', 'xfbml.render']);
        </script>    
        <fb:like    href='%@' 
                    send='false' 
                    layout='%@' 
                    width='%.0f' 
                    show_faces='%@' 
                    action='%@' 
                    colorscheme='%@' 
                    font='%@'
                    ></fb:like>
    </body>
</html>

and this is how I write events to Objective-C code:

- (void)didObserveFacebookEvent:(NSString *)fbEvent {
    if ([fbEvent isEqualToString:@"edge.create"] && [_delegate respondsToSelector:@selector(facebookLikeViewDidLike:)])
        [_delegate facebookLikeViewDidLike:self];
    else if ([fbEvent isEqualToString:@"edge.remove"] && [_delegate respondsToSelector:@selector(facebookLikeViewDidUnlike:)])
        [_delegate facebookLikeViewDidUnlike:self];
    else if ([fbEvent isEqualToString:@"xfbml.render"] && [_delegate respondsToSelector:@selector(facebookLikeViewDidRender:)])
        [_delegate facebookLikeViewDidRender:self];
}


- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    // Allow loading Like button XFBML from file
    if ([request.URL.scheme isEqualToString:@"file"])
        return YES;

    // Allow loading about:blank, etc.
    if ([request.URL.scheme isEqualToString:@"about"])
        return YES;

    // Block loading of 'event:*', our scheme for forwarding Facebook JS SDK events to native code
    else if ([request.URL.scheme isEqualToString:@"event"]) {
        [self didObserveFacebookEvent:request.URL.resourceSpecifier];
        return NO;
    }
  ....
}

- edge.create ( - ) - , ?

.

UPDATE: FB, , FBRELL, iOS UIWebView. , iOS? ? , .

+3
1

, edge.create HTML . , , , :

  • FacebookLikeView.html , , , . action='%@' action='like'.

  • load FacebookLikeView.m :

    [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.yourhost.com/FacebookLikeView.html"]]];
    
  • webView:shouldStartLoadWithRequest:navigationType:

    if ([request.URL.scheme isEqualToString:@"file"])
        return YES;
    

    if ([request.URL.host hasSuffix:@"yourhost.com"]) 
        return YES;
    

, , , , , .

+1

All Articles