2014-03-06 20 views
1

我想通過未通過Facebook登錄的用戶通過打開的圖共享對話分享自定義故事。我的代碼大部分是直接從Facebook的例子中取得的,因爲我們沒有任何圖像。這似乎最初起作用。該應用程序切換到正確格式化預覽Facebook。但是,預覽消失,「發佈」按鈕變灰。除了取消並返回到我們的應用程序,用戶沒有其他選擇。我也加倍檢查了所有屬性和名稱空間。對象在iOS的開放圖共享對話中消失

NSString *urlDeepLink = [NSString stringWithFormat:@"http://www.appname.com?dropSpot='%@'&user='%@'&name='%@'&lat=%f&long=%f&rad=%d",place.objectId, [User currentUser].objectId, geospot.name, geospot.location.latitude, geospot.location.longitude, geospot.radius]; 

NSMutableDictionary<FBGraphObject> *object = [FBGraphObject openGraphActionForPost]; 
object[@"type"] = @"appname:action"; 
object[@"title"] = geospot.name; 
object[@"description"] = place.detail; 
object[@"url"] = urlDeepLink; 

NSString *lat = [[NSNumber numberWithDouble:geospot.location.latitude]stringValue]; 
NSString *lng = [[NSNumber numberWithDouble:geospot.location.longitude]stringValue]; 

object[@"data" ] = @{ @"location": @{ @"latitude": lat, @"longitude": lng }}; 
object[@"fbsdk:create_object"] = @YES; 

// create an Open Graph action 
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject]; 
[action setObject:object forKey:@"action"]; 

// add expiration date for correct story tenses 
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; 
[dateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH:mm:ssZ"]; 
action[@"end_time"] = [dateFormatter stringFromDate:[NSDate date]]; 


// Check if the Facebook app is installed and we can present the share dialog 
FBOpenGraphActionShareDialogParams *params = [[FBOpenGraphActionShareDialogParams alloc] init]; 
params.action = action; 
params.actionType = @"appname:set"; 

// If the Facebook app is installed and we can present the share dialog 
if([FBDialogs canPresentShareDialogWithOpenGraphActionParams:params]) { 
    // Show the share dialog 
    [FBDialogs presentShareDialogWithOpenGraphAction:action 
              actionType:@"appname:set" 
           previewPropertyName:@"action" 
              handler:^(FBAppCall *call, NSDictionary *results, NSError *error) { 
               if(error) { 
                // There was an error 
                NSLog([NSString stringWithFormat:@"Error publishing story: %@", error.description]); 
               } else { 
                // Success 
                NSLog(@"result %@", results); 
               } 
              }]; 

    // If the Facebook app is NOT installed and we can't present the share dialog 
} else { 
    // FALLBACK: publish just a link using the Feed dialog 
    // Put together the dialog parameters 

    UIAlertView *alertUnableToPost = [[UIAlertView alloc]initWithTitle:@"Coudn't Post" message:@"We were unable to post your status to Facebook. This could be because you don't have the Facebook app installed on your phone." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
    [alertUnableToPost show]; 

    NSLog(@"Coudn't present share dialogue"); 
} 

回答

2

我明確地將「end_time」設置爲當前日期(退化代碼!)。刪除線可以讓它按照原樣工作。