Implemented the "wmf_locationFromURL" property in the NSUserActivity+WMFExtensions extension.
This commit is contained in:
parent
292f63c512
commit
7b5ad459af
@ -1,3 +1,4 @@
|
|||||||
|
@import CoreLocation;
|
||||||
@import Foundation;
|
@import Foundation;
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@ -46,6 +47,8 @@ extern NSString *const WMFNavigateToActivityNotification;
|
|||||||
|
|
||||||
- (nullable NSURL *)wmf_linkURL;
|
- (nullable NSURL *)wmf_linkURL;
|
||||||
|
|
||||||
|
- (nullable CLLocation *)wmf_locationFromURL;
|
||||||
|
|
||||||
- (NSURL *)wmf_contentURL;
|
- (NSURL *)wmf_contentURL;
|
||||||
|
|
||||||
+ (NSURL *)wmf_baseURLForActivityOfType:(WMFUserActivityType)type;
|
+ (NSURL *)wmf_baseURLForActivityOfType:(WMFUserActivityType)type;
|
||||||
|
@ -291,6 +291,18 @@ __attribute__((annotate("returns_localized_nsstring"))) static inline NSString *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (CLLocation *)wmf_locationFromURL {
|
||||||
|
NSNumber *latitude = self.userInfo[@"WMFCoordinatesLatitude"];
|
||||||
|
NSNumber *longitude = self.userInfo[@"WMFCoordinatesLongitude"];
|
||||||
|
|
||||||
|
if (latitude != nil && longitude != nil) {
|
||||||
|
return [[CLLocation alloc] initWithLatitude:(CLLocationDegrees)[latitude floatValue]
|
||||||
|
longitude:(CLLocationDegrees)[longitude floatValue]];
|
||||||
|
} else {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (NSURL *)wmf_contentURL {
|
- (NSURL *)wmf_contentURL {
|
||||||
return self.userInfo[@"WMFURL"];
|
return self.userInfo[@"WMFURL"];
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,16 @@
|
|||||||
XCTAssert([activity.userInfo[@"WMFCoordinatesLongitude"] isEqualToNumber:@4.895168]);
|
XCTAssert([activity.userInfo[@"WMFCoordinatesLongitude"] isEqualToNumber:@4.895168]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)testPlacesURLWithCoordinatesButNegatives {
|
||||||
|
NSURL *url = [NSURL URLWithString:@"wikipedia://places?coordinates=-34.603722,-58.381592"];
|
||||||
|
NSUserActivity *activity = [NSUserActivity wmf_activityForWikipediaScheme:url];
|
||||||
|
|
||||||
|
XCTAssertEqual(activity.wmf_type, WMFUserActivityTypePlaces);
|
||||||
|
XCTAssertNil(activity.webpageURL);
|
||||||
|
XCTAssert([activity.userInfo[@"WMFCoordinatesLatitude"] isEqualToNumber:@-34.603722]);
|
||||||
|
XCTAssert([activity.userInfo[@"WMFCoordinatesLongitude"] isEqualToNumber:@-58.381592]);
|
||||||
|
}
|
||||||
|
|
||||||
- (void)testPlacesURLWithCoordinatesButNoLongitude {
|
- (void)testPlacesURLWithCoordinatesButNoLongitude {
|
||||||
NSURL *url = [NSURL URLWithString:@"wikipedia://places?coordinates=52.370216,"];
|
NSURL *url = [NSURL URLWithString:@"wikipedia://places?coordinates=52.370216,"];
|
||||||
NSUserActivity *activity = [NSUserActivity wmf_activityForWikipediaScheme:url];
|
NSUserActivity *activity = [NSUserActivity wmf_activityForWikipediaScheme:url];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user