merge omer_links

This commit is contained in:
Omer Levy 2017-10-09 23:54:26 +03:00
commit adafa45380
1 changed files with 13 additions and 58 deletions

View File

@ -171,30 +171,16 @@ RCT_EXPORT_METHOD(createShortDynamicLink: (NSDictionary *) metadata resolver:(RC
} }
- (FIRDynamicLinkComponents *)getDynamicLinkComponentsFromMetadata:(NSDictionary *)metadata { - (FIRDynamicLinkComponents *)getDynamicLinkComponentsFromMetadata:(NSDictionary *)metadata {
NSMutableDictionary* dynamicLinkInfoMetadata = metadata[@"dynamicLinkInfo"]; NSDictionary* dynamicLinkInfoMetadata = metadata[@"dynamicLinkInfo"];
@try { @try {
NSURL *link = [NSURL URLWithString:dynamicLinkInfoMetadata[@"link"]]; NSURL *link = [NSURL URLWithString:dynamicLinkInfoMetadata[@"link"]];
[dynamicLinkInfoMetadata removeObjectForKey:@"link"];
FIRDynamicLinkComponents *components = FIRDynamicLinkComponents *components =
[FIRDynamicLinkComponents componentsWithLink:link domain:dynamicLinkInfoMetadata[@"dynamicLinkDomain"]]; [FIRDynamicLinkComponents componentsWithLink:link domain:dynamicLinkInfoMetadata[@"dynamicLinkDomain"]];
[dynamicLinkInfoMetadata removeObjectForKey:@"dynamicLinkDomain"];
[self setAndroidParameters:dynamicLinkInfoMetadata components:components]; [self setAndroidParameters:dynamicLinkInfoMetadata components:components];
[dynamicLinkInfoMetadata removeObjectForKey:@"androidInfo"];
[self setIosParameters:dynamicLinkInfoMetadata components:components]; [self setIosParameters:dynamicLinkInfoMetadata components:components];
[dynamicLinkInfoMetadata removeObjectForKey:@"iosInfo"];
[self setSocialMetaTagParameters:dynamicLinkInfoMetadata components:components]; [self setSocialMetaTagParameters:dynamicLinkInfoMetadata components:components];
[dynamicLinkInfoMetadata removeObjectForKey:@"socialMetaTagInfo"];
if ([dynamicLinkInfoMetadata count] > 0) {
@throw [NSException
exceptionWithName:@"Invalid arguments"
reason:@"Invalid arguments"
userInfo:nil];
}
return components; return components;
} }
@catch(NSException * e) { @catch(NSException * e) {
@ -203,109 +189,77 @@ RCT_EXPORT_METHOD(createShortDynamicLink: (NSDictionary *) metadata resolver:(RC
} }
} }
- (void)setAndroidParameters:(NSMutableDictionary *)metadata - (void)setAndroidParameters:(NSDictionary *)metadata
components:(FIRDynamicLinkComponents *)components { components:(FIRDynamicLinkComponents *)components {
NSMutableDictionary *androidParametersDict = metadata[@"androidInfo"]; NSDictionary *androidParametersDict = metadata[@"androidInfo"];
if (androidParametersDict) { if (androidParametersDict) {
if (!androidParametersDict[@"androidPackageName"]) { if (!androidParametersDict[@"androidPackageName"]) {
@throw [NSException @throw [NSException
exceptionWithName:@"Invalid arguments" exceptionWithName:@"missing arguments"
reason:@"no androidPackageName was specified" reason:@"no androidPackageName was specified."
userInfo:nil]; userInfo:nil];
} }
FIRDynamicLinkAndroidParameters *androidParams = [FIRDynamicLinkAndroidParameters FIRDynamicLinkAndroidParameters *androidParams = [FIRDynamicLinkAndroidParameters
parametersWithPackageName: androidParametersDict[@"androidPackageName"]]; parametersWithPackageName: androidParametersDict[@"androidPackageName"]];
[androidParametersDict removeObjectForKey:@"androidPackageName"];
if (androidParametersDict[@"androidFallbackLink"]) { if (androidParametersDict[@"androidFallbackLink"]) {
androidParams.fallbackURL = [NSURL URLWithString:androidParametersDict[@"androidFallbackLink"]]; androidParams.fallbackURL = [NSURL URLWithString:androidParametersDict[@"androidFallbackLink"]];
[androidParametersDict removeObjectForKey:@"androidFallbackLink"];
} }
if (androidParametersDict[@"androidMinPackageVersionCode"]) { if (androidParametersDict[@"androidMinPackageVersionCode"]) {
androidParams.minimumVersion = [androidParametersDict[@"androidMinPackageVersionCode"] integerValue]; androidParams.minimumVersion = [androidParametersDict[@"androidMinPackageVersionCode"] integerValue];
[androidParametersDict removeObjectForKey:@"androidMinPackageVersionCode"];
} }
if ([androidParametersDict count] > 0) {
@throw [NSException
exceptionWithName:@"Invalid arguments"
reason:@"Invalid arguments"
userInfo:nil];
}
components.androidParameters = androidParams; components.androidParameters = androidParams;
} }
} }
- (void)setIosParameters:(NSMutableDictionary *)metadata - (void)setIosParameters:(NSDictionary *)metadata
components:(FIRDynamicLinkComponents *)components { components:(FIRDynamicLinkComponents *)components {
NSMutableDictionary *iosParametersDict = metadata[@"iosInfo"]; NSDictionary *iosParametersDict = metadata[@"iosInfo"];
if (iosParametersDict) { if (iosParametersDict) {
if (!iosParametersDict[@"iosBundleId"]) { if (!iosParametersDict[@"iosBundleId"]) {
@throw [NSException @throw [NSException
exceptionWithName:@"Invalid arguments" exceptionWithName:@"missing arguments"
reason:@"no iosBundleId was specified" reason:@"no iosBundleId was specified."
userInfo:nil]; userInfo:nil];
} }
FIRDynamicLinkIOSParameters *iOSParams = [FIRDynamicLinkIOSParameters FIRDynamicLinkIOSParameters *iOSParams = [FIRDynamicLinkIOSParameters
parametersWithBundleID:iosParametersDict[@"iosBundleId"]]; parametersWithBundleID:iosParametersDict[@"iosBundleId"]];
[iosParametersDict removeObjectForKey:@"iosBundleId"];
if (iosParametersDict[@"iosAppStoreId"]) { if (iosParametersDict[@"iosAppStoreId"]) {
iOSParams.appStoreID = iosParametersDict[@"iosAppStoreId"]; iOSParams.appStoreID = iosParametersDict[@"iosAppStoreId"];
[iosParametersDict removeObjectForKey:@"iosAppStoreId"];
} }
if (iosParametersDict[@"iosCustomScheme"]) { if (iosParametersDict[@"iosCustomScheme"]) {
iOSParams.customScheme = iosParametersDict[@"iosCustomScheme"]; iOSParams.customScheme = iosParametersDict[@"iosCustomScheme"];
[iosParametersDict removeObjectForKey:@"iosCustomScheme"];
} }
if (iosParametersDict[@"iosFallbackLink"]) { if (iosParametersDict[@"iosFallbackLink"]) {
iOSParams.fallbackURL = [NSURL URLWithString:iosParametersDict[@"iosFallbackLink"]]; iOSParams.fallbackURL = [NSURL URLWithString:iosParametersDict[@"iosFallbackLink"]];
[iosParametersDict removeObjectForKey:@"iosFallbackLink"];
} }
if (iosParametersDict[@"iosIpadBundleId"]) { if (iosParametersDict[@"iosIpadBundleId"]) {
iOSParams.iPadBundleID = iosParametersDict[@"iosIpadBundleId"]; iOSParams.iPadBundleID = iosParametersDict[@"iosIpadBundleId"];
[iosParametersDict removeObjectForKey:@"iosIpadBundleId"];
} }
if (iosParametersDict[@"iosIpadFallbackLink"]) { if (iosParametersDict[@"iosIpadFallbackLink"]) {
iOSParams.iPadFallbackURL = [NSURL URLWithString:iosParametersDict[@"iosIpadFallbackLink"]]; iOSParams.iPadFallbackURL = [NSURL URLWithString:iosParametersDict[@"iosIpadFallbackLink"]];
[iosParametersDict removeObjectForKey:@"iosIpadFallbackLink"];
} }
if (iosParametersDict[@"iosMinPackageVersionCode"]) { if (iosParametersDict[@"iosMinPackageVersionCode"]) {
iOSParams.minimumAppVersion = iosParametersDict[@"iosMinPackageVersionCode"]; iOSParams.minimumAppVersion = iosParametersDict[@"iosMinPackageVersionCode"];
[iosParametersDict removeObjectForKey:@"iosMinPackageVersionCode"];
}
if ([iosParametersDict count] > 0) {
@throw [NSException
exceptionWithName:@"Invalid arguments"
reason:@"Invalid arguments"
userInfo:nil];
} }
components.iOSParameters = iOSParams; components.iOSParameters = iOSParams;
} }
} }
- (void)setSocialMetaTagParameters:(NSMutableDictionary *)metadata - (void)setSocialMetaTagParameters:(NSDictionary *)metadata
components:(FIRDynamicLinkComponents *)components { components:(FIRDynamicLinkComponents *)components {
NSMutableDictionary *socialParamsDict = metadata[@"socialMetaTagInfo"]; NSDictionary *socialParamsDict = metadata[@"socialMetaTagInfo"];
if (socialParamsDict) { if (socialParamsDict) {
FIRDynamicLinkSocialMetaTagParameters *socialParams = [FIRDynamicLinkSocialMetaTagParameters parameters]; FIRDynamicLinkSocialMetaTagParameters *socialParams = [FIRDynamicLinkSocialMetaTagParameters parameters];
if (socialParamsDict[@"socialTitle"]) { if (socialParamsDict[@"socialTitle"]) {
socialParams.title = socialParamsDict[@"socialTitle"]; socialParams.title = socialParamsDict[@"socialTitle"];
[socialParamsDict removeObjectForKey:@"socialTitle"];
} }
if (socialParamsDict[@"socialDescription"]) { if (socialParamsDict[@"socialDescription"]) {
socialParams.descriptionText = socialParamsDict[@"socialDescription"]; socialParams.descriptionText = socialParamsDict[@"socialDescription"];
[socialParamsDict removeObjectForKey:@"socialDescription"];
} }
if (socialParamsDict[@"socialImageLink"]) { if (socialParamsDict[@"socialImageLink"]) {
socialParams.imageURL = [NSURL URLWithString:socialParamsDict[@"socialImageLink"]]; socialParams.imageURL = [NSURL URLWithString:socialParamsDict[@"socialImageLink"]];
[socialParamsDict removeObjectForKey:@"socialImageLink"];
}
if ([socialParamsDict count] > 0) {
@throw [NSException
exceptionWithName:@"Invalid arguments"
reason:@"Invalid arguments"
userInfo:nil];
} }
components.socialMetaTagParameters = socialParams; components.socialMetaTagParameters = socialParams;
} }
@ -333,3 +287,4 @@ RCT_EXPORT_METHOD(createShortDynamicLink: (NSDictionary *) metadata resolver:(RC
@end @end
#endif #endif