Ho onestamente trascorso ore su questo tentativo di farlo funzionare. Purtroppo Facebook & App Link's documentation non è abbastanza chiaro. Anche lo App Links video from F8.Utilizzo dell'API di hosting collegamenti di app per il collegamento condiviso su Facebook dall'app iOS
App Requisiti:
- link per FB come una storia Open Graph, che gli utenti possono fare clic su per portarli direttamente nella mia app e fare compiti specifici (la mia applicazione ha bisogno di ricevere i parametri specifici da il collegamento)
- Condividere il collegamento a FB senza accesso FB (ovvero tramite la finestra di dialogo Condividi e passare all'app FB iOS nativa anziché utilizzare le chiamate API).
Progress finora:
Sto utilizzando il seguente codice per creare il ospitato App Link (come ho solo contenuti mobili) come da FB developer's website under Publishing iOS SDK.
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@"{My app name}", @"name",
{custom URL}, @"al:iphone:url",
@"{app store ID}", @"al:iphone:app_store_id",
@"{My app name}", @"al:iphone:app_name",
@"{\"should_fallback\": false}", @"web",
fbAccessToken, @"access_token",
nil
];
/* make the API call */
[FBRequestConnection startWithGraphPath:@"/{FB app id}/app_link_hosts"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(
FBRequestConnection *connection,
id result,
NSError *error
) {
/* handle the result */
NSLog(@"Result = %@",result);
if(error) NSLog(@"error = %@",error);
}];
Poi ho postare la storia di OG su FB (questo è un messaggio che va bene ma senza un URL corretto)
// Create OG object
id<FBGraphObject> object =
[FBGraphObject openGraphObjectForPostWithType:@"{app name}:{FB object_name}"
title:@"Test Link"
image:@"https://cdn3.iconfinder.com/data/icons/picons-social/57/56-apple-512.png" // hosted wallpaper with unique id for background
url:nil // Assuming I need to put the url to the app link host object here??
description:@"Click to on this test link!"];
// Create an action
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
// Link the object to the action
[action setObject:object forKey:@"{FB object name}"];
// Check if the Facebook app is installed and we can present the share dialog
FBOpenGraphActionParams *params = [[FBOpenGraphActionParams alloc] init];
params.action = action;
params.actionType = @"{app name}:{FB action name}";
// 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:@"{app name}:{FB action name}"
previewPropertyName:@"{FB object name}"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(@"Error publishing story: %@", error.description);
} else {
// Success
NSLog(@"result %@", results);
}
}];
}
Per gestire l'URL in arrivo quando un utente fa clic sul link nella storia FB OG Ho aggiunto il seguente codice per AppDelegate.m come da documentazione FB - vedere Handling incoming links
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
BOOL urlWasHandled =
[FBAppCall handleOpenURL:url
sourceApplication:sourceApplication
fallbackHandler:
^(FBAppCall *call) {
// Parse the incoming URL to look for a target_url parameter
NSString *query = [url query];
NSDictionary *params = [self parseURLParams:query];
// Check if target URL exists
NSString *appLinkDataString = [params valueForKey:@"al_applink_data"];
if (appLinkDataString) {
NSError *error = nil;
NSDictionary *applinkData =
[NSJSONSerialization JSONObjectWithData:[appLinkDataString dataUsingEncoding:NSUTF8StringEncoding]
options:0
error:&error];
if (!error &&
[applinkData isKindOfClass:[NSDictionary class]] &&
applinkData[@"target_url"]) {
NSString *targetURLString = applinkData[@"target_url"];
// Show the incoming link in an alert
// Your code to direct the user to the
// appropriate flow within your app goes here
[[[UIAlertView alloc] initWithTitle:@"Received link:"
message:targetURLString
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] show];
}
}
}];
return urlWasHandled;
}
// A function for parsing URL parameters
- (NSDictionary*)parseURLParams:(NSString *)query {
NSArray *pairs = [query componentsSeparatedByString:@"&"];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
for (NSString *pair in pairs) {
NSArray *kv = [pair componentsSeparatedByString:@"="];
NSString *val = [[kv objectAtIndex:1]
stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[params setObject:val forKey:[kv objectAtIndex:0]];
}
return params;
}
Qualcuno ha stato in grado di ottenere questo lavoro ? Non sono ancora chiaro su come funziona il collegamento app ospitato e dove metterlo (presumo dovrebbe andare nel parametro 'url' quando si chiama il metodo openGraphObjectForPostWithType FBGraphObject.
Non voglio davvero creare un sito Web per archiviare tutti gli URL e aggiungere i meta tag App Link (dovrei fare tutto questo tramite l'app dato che ogni App Link sarà dinamico e unico per ogni utente da cui viene generato nell'app). !
Please help
si può includere i risultati delle richieste fatte da una delle frammenti di codice di cui sopra? Un paio di osservazioni che ho: 1.) richiediamo che le chiamate dell'host del link dell'app abbiano un token di accesso all'app (piuttosto che un utente), quindi in genere tali richieste non dovrebbero essere fatte su un client mobile. 2.) Per gli oggetti OG, dovresti usare l'URL fb.me che ti diamo una volta creato l'host link dell'app (vedi questo documento su come ottenere l'URL fb.me - https://developers.facebook.com/docs/applinks/hosting-api) –
@MingLi Grazie per la direzione! Ora ho il token di accesso dell'app che funziona. Farò qualche test per vedere se riesco a ottenere l'URL personalizzato che passa informazioni alla mia app correttamente. C'è un limite al numero di host di link app che l'app può avere e per quanto tempo sono attivi? – Tim
@MingLi La mia app pubblica ora OG con il link App in hosting. Quando faccio clic sul collegamento in FB iOS, passa alla mia app, ma NSString * query = [url query] (in AppDelegate) restituisce null nonostante venga restituito un URL di massa? Questo è basato sul codice dalla pagina degli sviluppatori FB. Qualche idea su cosa potrebbe essere sbagliato? – Tim