2014-11-13 8 views
5

Come aggiungere la posizione non solo NSString ma con latitudine e longitudine, quindi mostra anche una mappa nel Calendario?Aggiungi posizione a EKEvent Calendario IOS

<EKCalendarItem> 

https://developer.apple.com/LIBRARY/ios/documentation/EventKit/Reference/EKCalendarItemClassRef/index.html#//apple_ref/occ/instp/EKCalendarItem/location

@property(nonatomic, copy) NSString *location; 

Codice:

EKEventStore *store = [[EKEventStore alloc] init]; 
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { 
    if (!granted) { return; } 
    EKEvent *event = [EKEvent eventWithEventStore:store]; 
    event.title = @"Event Title"; 
    event.startDate = [NSDate date]; //today 
    event.endDate = [event.startDate dateByAddingTimeInterval:60*60]; //set 1 hour meeting 
    [email protected]"Note"; 
    [email protected]"Eiffel Tower,Paris"; //how do i add Lat & long/CLLocation? 
    event.URL=[NSURL URLWithString:shareUrl]; 
    [event setCalendar:[store defaultCalendarForNewEvents]]; 
    NSError *err = nil; 
    [store saveEvent:event span:EKSpanThisEvent commit:YES error:&err]; 
    NSString *savedEventId = event.eventIdentifier; //this is so you can access this event later 
}]; 

Example

+0

Prova a fare quanto indicato nelle ans http://stackoverflow.com/questions/16647996/get-location- nome-da-latitudine-longitudine-in-ios – Revinder

+0

Trovato una soluzione per questo ancora? Sono sulla stessa barca – jsetting32

+0

@ jsetting32 Ancora nessuna soluzione, penso che non sia possibile forse: P – Metalhead1247

risposta

0

si potrebbe essere in grado di utilizzare setValue: Forkey: sul EKEvent dopo aver creato un EKStructuredLocation, la chiave è 'structuredLocation'

5

È piuttosto strano che non ci sia documentazione per questo, ma questo è il modo in cui aggiungi una posizione geografica a un evento del calendario.

EKStructuredLocation* structuredLocation = [EKStructuredLocation locationWithTitle:@"Location"]; // locationWithTitle has the same behavior as event.location 
CLLocation* location = [[CLLocation alloc] initWithLatitude:0.0 longitude:0.0]; 
structuredLocation.geoLocation = location; 

[event setValue:structuredLocation forKey:@"structuredLocation"]; 
+0

Non dubito che questo funzioni. Ma la documentazione menziona l'uso di EKStructuredLocation per essere specificamente per l'impostazione di posizioni Geofencing. Eventuali problemi che potrebbero sorgere con questa soluzione? – SpacyRicochet

+1

@spacyRicochet - Non ho avuto alcun problema con questo metodo. Da quello che ho giocato, questa è l'unica soluzione per aggiungere una mappa al tuo evento del calendario. Penso davvero che il problema sia che la documentazione deve essere aggiornata. O hanno implementato questa funzionalità ed è stato un errore, o semplicemente si sono dimenticati di includerlo nella loro documentazione. Indipendentemente da ciò, funziona. –

+0

Non sembra funzionare correttamente per me, anche se potrebbe essere solo il simulatore a non piacerle. Provalo sul dispositivo più tardi. – SpacyRicochet

7

La proprietà structuredLocation è disponibile su iOS 9, anche se la documentazione EKEvent non ne parla, ma structuredLocation esiste nel file di intestazione EKEvent pubblico, e si può controllare all'interno Xcode. Non c'è bisogno di usare KVC per impostarlo dopo iOS 9.

versione Swift come segue:

let location = CLLocation(latitude: 25.0340, longitude: 121.5645) 
let structuredLocation = EKStructuredLocation(title: placeName) // same title with ekEvent.location 
structuredLocation.geoLocation = location 
ekEvent.structuredLocation = structuredLocation 
Problemi correlati