FDLURLComponents.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. /*
  2. * Copyright 2018 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. NS_ASSUME_NONNULL_BEGIN
  18. /**
  19. * @abstract Enum used to define the desired path length for shortened Dynamic Link URLs.
  20. */
  21. typedef NS_ENUM(NSInteger, FIRShortDynamicLinkPathLength) {
  22. /**
  23. * Uses the server-default for the path length. See https://goo.gl/8yDAqC for more information.
  24. */
  25. FIRShortDynamicLinkPathLengthDefault = 0,
  26. /** Typical short link for non-sensitive links. */
  27. FIRShortDynamicLinkPathLengthShort,
  28. /** Short link with an extra long path for great difficulty in guessing. */
  29. FIRShortDynamicLinkPathLengthUnguessable,
  30. } NS_SWIFT_NAME(ShortDynamicLinkPathLength);
  31. /**
  32. * @abstract The definition of the completion block used by URL shortener.
  33. * @param shortURL Shortened URL.
  34. * @param warnings Warnings that describe usability or function limitations of the generated
  35. * short link. Usually presence of warnings means parameteres format error, parametres value
  36. * error or missing parameter.
  37. * @param error Error if URL can't be shortened.
  38. */
  39. typedef void (^FIRDynamicLinkShortenerCompletion)(NSURL *_Nullable shortURL,
  40. NSArray<NSString *> *_Nullable warnings,
  41. NSError *_Nullable error)
  42. NS_SWIFT_NAME(DynamicLinkShortenerCompletion);
  43. /**
  44. * @class FIRDynamicLinkGoogleAnalyticsParameters
  45. * @abstract The Dynamic Link analytics parameters.
  46. */
  47. NS_SWIFT_NAME(DynamicLinkGoogleAnalyticsParameters)
  48. @interface FIRDynamicLinkGoogleAnalyticsParameters : NSObject
  49. /**
  50. * @property source
  51. * @abstract The utm_source analytics parameter.
  52. */
  53. @property(nonatomic, copy, nullable) NSString *source;
  54. /**
  55. * @property medium
  56. * @abstract The utm_medium analytics parameter.
  57. */
  58. @property(nonatomic, copy, nullable) NSString *medium;
  59. /**
  60. * @property campaign
  61. * @abstract The utm_campaign analytics parameter.
  62. */
  63. @property(nonatomic, copy, nullable) NSString *campaign;
  64. /**
  65. * @property term
  66. * @abstract The utm_term analytics parameter.
  67. */
  68. @property(nonatomic, copy, nullable) NSString *term;
  69. /**
  70. * @property content
  71. * @abstract The utm_content analytics parameter.
  72. */
  73. @property(nonatomic, copy, nullable) NSString *content;
  74. /**
  75. * @method parametersWithSource:medium:campaign:
  76. * @abstract The preferred factory method for creating the analytics parameters object. It includes
  77. * the commonly-used source, medium, and campaign fields.
  78. * @param source The utm_source analytics parameter.
  79. * @param medium The utm_medium analytics parameter.
  80. * @param campaign The utm_campaign analytics parameter.
  81. * @return Returns An object to be used with FIRDynamicLinkURLComponents to add analytics parameters
  82. * to a generated Dynamic Link URL.
  83. */
  84. + (instancetype)parametersWithSource:(NSString *)source
  85. medium:(NSString *)medium
  86. campaign:(NSString *)campaign
  87. NS_SWIFT_UNAVAILABLE("Use init(source:medium:campaign:)");
  88. /**
  89. * @method parameters
  90. * @abstract A factory method for creating the analytics parameters object.
  91. * @return Returns an object to be used with FIRDynamicLinkURLComponents to add analytics parameters
  92. * to a generated Dynamic Link URL.
  93. */
  94. + (instancetype)parameters NS_SWIFT_UNAVAILABLE("Use init()");
  95. /**
  96. * @method initWithSource:medium:campaign:
  97. * @abstract The preferred instance method for creating the analytics parameters object. It
  98. * includes the commonly-used source, medium, and campaign fields.
  99. * @param source The utm_source analytics parameter.
  100. * @param medium The utm_medium analytics parameter.
  101. * @param campaign The utm_campaign analytics parameter.
  102. * @return Returns An object to be used with FIRDynamicLinkURLComponents to add analytics parameters
  103. * to a generated Dynamic Link URL.
  104. */
  105. - (instancetype)initWithSource:(NSString *)source
  106. medium:(NSString *)medium
  107. campaign:(NSString *)campaign;
  108. /**
  109. * @method init
  110. * @return Returns an object to be used with FIRDynamicLinkURLComponents to add analytics parameters
  111. * to a generated Dynamic Link URL.
  112. */
  113. - (instancetype)init;
  114. @end
  115. /**
  116. * @class FIRDynamicLinkIOSParameters
  117. * @abstract The Dynamic Link iOS parameters.
  118. */
  119. NS_SWIFT_NAME(DynamicLinkIOSParameters)
  120. @interface FIRDynamicLinkIOSParameters : NSObject
  121. /**
  122. * @property bundleID
  123. * @abstract The bundle ID of the iOS app to use to open the link.
  124. */
  125. @property(nonatomic, copy, nullable, readonly) NSString *bundleID;
  126. /**
  127. * @property appStoreID
  128. * @abstract The appStore ID of the iOS app in AppStore.
  129. */
  130. @property(nonatomic, copy, nullable) NSString *appStoreID;
  131. /**
  132. * @property fallbackURL
  133. * @abstract The link to open when the app isn't installed. Specify this to do something other than
  134. * install the app from the App Store when the app isn't installed, such as open the mobile
  135. * web version of the content, or display a promotional page for the app.
  136. */
  137. @property(nonatomic, nullable) NSURL *fallbackURL;
  138. /**
  139. * @property customScheme
  140. * @abstract The target app's custom URL scheme, if defined to be something other than the app's
  141. * bundle ID
  142. */
  143. @property(nonatomic, copy, nullable) NSString *customScheme;
  144. /**
  145. * @property iPadBundleID
  146. * @abstract The bundle ID of the iOS app to use on iPads to open the link. This is only required if
  147. * there are separate iPhone and iPad applications.
  148. */
  149. @property(nonatomic, copy, nullable) NSString *iPadBundleID;
  150. /**
  151. * @property iPadFallbackURL
  152. * @abstract The link to open on iPads when the app isn't installed. Specify this to do something
  153. * other than install the app from the App Store when the app isn't installed, such as open the
  154. * web version of the content, or display a promotional page for the app.
  155. */
  156. @property(nonatomic, nullable) NSURL *iPadFallbackURL;
  157. /**
  158. @property minimumAppVersion
  159. @abstract The the minimum version of your app that can open the link. If the
  160. * installed app is an older version, the user is taken to the AppStore to upgrade the app.
  161. * Note: It is app's developer responsibility to open AppStore when received link declares
  162. * higher minimumAppVersion than currently installed.
  163. */
  164. @property(nonatomic, copy, nullable) NSString *minimumAppVersion;
  165. /**
  166. * @method parametersWithBundleID:
  167. * @abstract A method for creating the iOS parameters object.
  168. * @param bundleID The bundle ID of the iOS app to use to open the link.
  169. * @return Returns an object to be used with FIRDynamicLinkURLComponents to add iOS parameters to a
  170. * generated Dynamic Link URL.
  171. */
  172. + (instancetype)parametersWithBundleID:(NSString *)bundleID
  173. NS_SWIFT_UNAVAILABLE("Use initWithBundleID()");
  174. /**
  175. * @method initWithBundleID:
  176. * @abstract A method for creating the iOS parameters object.
  177. * @param bundleID The bundle ID of the iOS app to use to open the link.
  178. * @return Returns an object to be used with FIRDynamicLinkURLComponents to add iOS parameters to a
  179. * generated Dynamic Link URL.
  180. */
  181. - (instancetype)initWithBundleID:(NSString *)bundleID;
  182. @end
  183. /**
  184. * @class FIRDynamicLinkItunesConnectAnalyticsParameters
  185. * @abstract The Dynamic Link iTunes Connect parameters.
  186. */
  187. NS_SWIFT_NAME(DynamicLinkItunesConnectAnalyticsParameters)
  188. @interface FIRDynamicLinkItunesConnectAnalyticsParameters : NSObject
  189. /**
  190. * @property affiliateToken
  191. * @abstract The iTunes Connect affiliate token.
  192. */
  193. @property(nonatomic, copy, nullable) NSString *affiliateToken;
  194. /**
  195. * @property campaignToken
  196. * @abstract The iTunes Connect campaign token.
  197. */
  198. @property(nonatomic, copy, nullable) NSString *campaignToken;
  199. /**
  200. * @property providerToken
  201. * @abstract The iTunes Connect provider token.
  202. */
  203. @property(nonatomic, copy, nullable) NSString *providerToken;
  204. /**
  205. * @method parameters
  206. * @abstract A method for creating the iTunes Connect parameters object.
  207. * @return Returns an object to be used with FIRDynamicLinkURLComponents to add iTunes Connect
  208. * parameters to a generated Dynamic Link URL.
  209. */
  210. + (instancetype)parameters NS_SWIFT_UNAVAILABLE("Use init()");
  211. /**
  212. * @method init
  213. * @abstract A method for creating the iTunes Connect parameters object.
  214. * @return Returns an object to be used with FIRDynamicLinkURLComponents to add iTunes Connect
  215. * parameters to a generated Dynamic Link URL.
  216. */
  217. - (instancetype)init;
  218. @end
  219. /**
  220. * @class FIRDynamicLinkAndroidParameters
  221. * @abstract The Dynamic Link Android parameters.
  222. */
  223. NS_SWIFT_NAME(DynamicLinkAndroidParameters)
  224. @interface FIRDynamicLinkAndroidParameters : NSObject
  225. /**
  226. * @property packageName
  227. * @abstract The Android app's package name.
  228. */
  229. @property(nonatomic, copy, nullable, readonly) NSString *packageName;
  230. /**
  231. * @property fallbackURL
  232. * @abstract The link to open when the app isn't installed. Specify this to do something other than
  233. * install the app from the Play Store when the app isn't installed, such as open the mobile web
  234. * version of the content, or display a promotional page for the app.
  235. */
  236. @property(nonatomic, nullable) NSURL *fallbackURL;
  237. /**
  238. @property minimumVersion
  239. @abstract The version code of the minimum version of your app that can open the link. If the
  240. * installed app is an older version, the user is taken to the Play Store to upgrade the app.
  241. */
  242. @property(nonatomic) NSInteger minimumVersion;
  243. /**
  244. * @method parametersWithPackageName:
  245. * @abstract A method for creating the Android parameters object.
  246. * @param packageName The Android app's package name.
  247. * @return Returns an object to be used with FIRDynamicLinkURLComponents to add Android parameters
  248. * to a generated Dynamic Link URL.
  249. */
  250. + (instancetype)parametersWithPackageName:(NSString *)packageName
  251. NS_SWIFT_UNAVAILABLE("Use initWithPackageName()");
  252. /**
  253. * @method initWithPackageName:
  254. * @abstract A method for creating the Android parameters object.
  255. * @param packageName The Android app's package name.
  256. * @return Returns an object to be used with FIRDynamicLinkURLComponents to add Android parameters
  257. * to a generated Dynamic Link URL.
  258. */
  259. - (instancetype)initWithPackageName:(NSString *)packageName;
  260. @end
  261. /**
  262. * @class FIRDynamicLinkSocialMetaTagParameters
  263. * @abstract The Dynamic Link Social Meta Tag parameters.
  264. */
  265. NS_SWIFT_NAME(DynamicLinkSocialMetaTagParameters)
  266. @interface FIRDynamicLinkSocialMetaTagParameters : NSObject
  267. /**
  268. * @property title
  269. * @abstract The title to use when the Dynamic Link is shared in a social post.
  270. */
  271. @property(nonatomic, copy, nullable) NSString *title;
  272. /**
  273. * @property descriptionText
  274. * @abstract The description to use when the Dynamic Link is shared in a social post.
  275. */
  276. @property(nonatomic, copy, nullable) NSString *descriptionText;
  277. /**
  278. * @property imageURL
  279. * @abstract The URL to an image related to this link.
  280. */
  281. @property(nonatomic, nullable) NSURL *imageURL;
  282. /**
  283. * @method parameters
  284. * @abstract A method for creating the Social Meta Tag parameters object.
  285. * @return Returns an object to be used with FIRDynamicLinkURLComponents to add Social Meta Tag
  286. * parameters to a generated Dynamic Link URL.
  287. */
  288. + (instancetype)parameters NS_SWIFT_UNAVAILABLE("Use init()");
  289. /**
  290. * @method init
  291. * @abstract A method for creating the Social Meta Tag parameters object.
  292. * @return Returns an object to be used with FIRDynamicLinkURLComponents to add Social Meta Tag
  293. * parameters to a generated Dynamic Link URL.
  294. */
  295. - (instancetype)init;
  296. @end
  297. /**
  298. * @class FIRDynamicLinkNavigationInfoParameters
  299. * @abstract Options class for defining navigation behavior of the Dynamic Link.
  300. */
  301. NS_SWIFT_NAME(DynamicLinkNavigationInfoParameters)
  302. @interface FIRDynamicLinkNavigationInfoParameters : NSObject
  303. /**
  304. * @property forcedRedirectEnabled
  305. * @abstract Property defines should forced non-interactive redirect be used when link is tapped on
  306. * mobile device. Default behavior is to disable force redirect and show interstitial page where
  307. * user tap will initiate navigation to the App (or AppStore if not installed). Disabled force
  308. * redirect normally improves reliability of the click.
  309. */
  310. @property(nonatomic, getter=isForcedRedirectEnabled) BOOL forcedRedirectEnabled;
  311. /**
  312. * @method parameters
  313. * @abstract A method for creating the Navigation Info parameters object.
  314. * @return Returns an object to be used with FIRDynamicLinkURLComponents to add Navigation Info
  315. * parameters to a generated Dynamic Link URL.
  316. */
  317. + (instancetype)parameters NS_SWIFT_UNAVAILABLE("Use init()");
  318. /**
  319. * @method init
  320. * @abstract A method for creating the Navigation Info parameters object.
  321. * @return Returns an object to be used with FIRDynamicLinkURLComponents to add Navigation Info
  322. * parameters to a generated Dynamic Link URL.
  323. */
  324. - (instancetype)init;
  325. @end
  326. /**
  327. * @class FIRDynamicLinkOtherPlatformParameters
  328. * @abstract Options class for defining other platform(s) parameters of the Dynamic Link.
  329. * Other here means not covered by specific parameters (not iOS and not Android).
  330. */
  331. NS_SWIFT_NAME(DynamicLinkOtherPlatformParameters)
  332. @interface FIRDynamicLinkOtherPlatformParameters : NSObject
  333. /**
  334. * @property fallbackUrl
  335. * @abstract Property defines fallback URL to navigate to when Dynamic Link is clicked on
  336. * other platform.
  337. */
  338. @property(nonatomic, nullable) NSURL *fallbackUrl;
  339. /**
  340. * @method parameters
  341. * @abstract A method for creating the Other platform parameters object.
  342. * @return Returns an object to be used with FIRDynamicLinkURLComponents to add Other Platform
  343. * parameters to a generated Dynamic Link URL.
  344. */
  345. + (instancetype)parameters NS_SWIFT_UNAVAILABLE("Use init()");
  346. /**
  347. * @method init
  348. * @abstract A method for creating the Other platform parameters object.
  349. * @return Returns an object to be used with FIRDynamicLinkURLComponents to add Other Platform
  350. * parameters to a generated Dynamic Link URL.
  351. */
  352. - (instancetype)init;
  353. @end
  354. /**
  355. * @class FIRDynamicLinkComponentsOptions
  356. * @abstract Options class for defining how Dynamic Link URLs are generated.
  357. */
  358. NS_SWIFT_NAME(DynamicLinkComponentsOptions)
  359. @interface FIRDynamicLinkComponentsOptions : NSObject
  360. /**
  361. * @property pathLength
  362. * @abstract Specifies the length of the path component of a short Dynamic Link.
  363. */
  364. @property(nonatomic) FIRShortDynamicLinkPathLength pathLength;
  365. /**
  366. * @method options
  367. * @abstract A method for creating the Dynamic Link components options object.
  368. * @return Returns an object to be used with FIRDynamicLinkURLComponents to specify options related
  369. * to the generation of Dynamic Link URLs.
  370. */
  371. + (instancetype)options NS_SWIFT_UNAVAILABLE("Use init()");
  372. /**
  373. * @method init
  374. * @abstract A method for creating the Dynamic Link components options object.
  375. * @return Returns an object to be used with FIRDynamicLinkURLComponents to specify options related
  376. * to the generation of Dynamic Link URLs.
  377. */
  378. - (instancetype)init;
  379. @end
  380. /**
  381. * @class FIRDynamicLinkComponents
  382. * @abstract The class used for Dynamic Link URL generation; supports creation of short and long
  383. * Dynamic Link URLs. Short URLs will have a domain and a randomized path; long URLs will have a
  384. * domain and a query that contains all of the Dynamic Link parameters.
  385. */
  386. NS_SWIFT_NAME(DynamicLinkComponents)
  387. @interface FIRDynamicLinkComponents : NSObject
  388. /**
  389. * @property analyticsParameters
  390. * @abstract Applies Analytics parameters to a generated Dynamic Link URL.
  391. */
  392. @property(nonatomic, nullable) FIRDynamicLinkGoogleAnalyticsParameters *analyticsParameters;
  393. /**
  394. * @property socialMetaTagParameters
  395. * @abstract Applies Social Meta Tag parameters to a generated Dynamic Link URL.
  396. */
  397. @property(nonatomic, nullable) FIRDynamicLinkSocialMetaTagParameters *socialMetaTagParameters;
  398. /**
  399. * @property iOSParameters
  400. * @abstract Applies iOS parameters to a generated Dynamic Link URL.
  401. */
  402. @property(nonatomic, nullable) FIRDynamicLinkIOSParameters *iOSParameters;
  403. /**
  404. * @property iTunesConnectParameters
  405. * @abstract Applies iTunes Connect parameters to a generated Dynamic Link URL.
  406. */
  407. @property(nonatomic, nullable)
  408. FIRDynamicLinkItunesConnectAnalyticsParameters *iTunesConnectParameters;
  409. /**
  410. * @property androidParameters
  411. * @abstract Applies Android parameters to a generated Dynamic Link URL.
  412. */
  413. @property(nonatomic, nullable) FIRDynamicLinkAndroidParameters *androidParameters;
  414. /**
  415. * @property navigationInfoParameters
  416. * @abstract Applies Navigation Info parameters to a generated Dynamic Link URL.
  417. */
  418. @property(nonatomic, nullable) FIRDynamicLinkNavigationInfoParameters *navigationInfoParameters;
  419. /**
  420. * @property otherPlatformParameters
  421. * @abstract Applies Other platform parameters to a generated Dynamic Link URL.
  422. */
  423. @property(nonatomic, nullable) FIRDynamicLinkOtherPlatformParameters *otherPlatformParameters;
  424. /**
  425. * @property options
  426. * @abstract Defines behavior for generating Dynamic Link URLs.
  427. */
  428. @property(nonatomic, nullable) FIRDynamicLinkComponentsOptions *options;
  429. /**
  430. * @property link
  431. * @abstract The link the target app will open. You can specify any URL the app can handle, such as
  432. * a link to the app's content, or a URL that initiates some app-specific logic such as
  433. * crediting the user with a coupon, or displaying a specific welcome screen. This link must be
  434. * a well-formatted URL, be properly URL-encoded, and use the HTTP or HTTPS scheme.
  435. */
  436. @property(nonatomic) NSURL *link;
  437. /**
  438. * @property domain
  439. * @abstract The Firebase project's Dynamic Links domain. You can find this value in the Dynamic
  440. * Links section of the Firebase console.
  441. * https://console.firebase.google.com/
  442. */
  443. @property(nonatomic, nullable, copy) NSString *domain;
  444. /**
  445. * @property url
  446. * @abstract A generated long Dynamic Link URL.
  447. */
  448. @property(nonatomic, nullable, readonly) NSURL *url;
  449. /**
  450. * @method componentsWithLink:domainURIPrefix:
  451. * @abstract Generates a Dynamic Link URL components object with the minimum necessary parameters
  452. * set to generate a fully-functional Dynamic Link.
  453. * @param link Deep link to be stored in created Dynamic link. This link also called "payload" of
  454. * the Dynamic link.
  455. * @param domainURIPrefix Domain URI Prefix of your App. This value must be your assigned
  456. * domain from the Firebase console. (e.g. https://xyz.page.link) The domain URI prefix must
  457. * start with a valid HTTPS scheme (https://).
  458. * @return Returns an instance of FIRDynamicLinkComponents if the parameters succeed validation,
  459. * else returns nil.
  460. */
  461. + (nullable instancetype)componentsWithLink:(NSURL *)link
  462. domainURIPrefix:(NSString *)domainURIPrefix
  463. NS_SWIFT_UNAVAILABLE("Use init(link:domainURIPrefix:)");
  464. /**
  465. * @method initWithLink:domainURIPrefix:
  466. * @abstract Generates a Dynamic Link URL components object with the minimum necessary parameters
  467. * set to generate a fully-functional Dynamic Link.
  468. * @param link Deep link to be stored in created Dynamic link. This link also called "payload" of
  469. * the Dynamic link.
  470. * @param domainURIPrefix Domain URI Prefix of your App. This value must be your assigned
  471. * domain from the Firebase console. (e.g. https://xyz.page.link) The domain URI prefix must
  472. * start with a valid HTTPS scheme (https://).
  473. * @return Returns an instance of FIRDynamicLinkComponents if the parameters succeed validation,
  474. * else returns nil.
  475. */
  476. - (nullable instancetype)initWithLink:(NSURL *)link domainURIPrefix:(NSString *)domainURIPrefix;
  477. /**
  478. * @method shortenURL:options:completion:
  479. * @abstract Shortens a Dynamic Link URL. This method may be used for shortening a custom URL that
  480. * was not generated using FIRDynamicLinkComponents.
  481. * @param url A properly-formatted long Dynamic Link URL.
  482. * @param completion A block to be executed upon completion of the shortening attempt. It is
  483. * guaranteed to be executed once and on the main thread.
  484. */
  485. + (void)shortenURL:(NSURL *)url
  486. options:(FIRDynamicLinkComponentsOptions *_Nullable)options
  487. completion:(FIRDynamicLinkShortenerCompletion)completion;
  488. /**
  489. * @method shortenWithCompletion:
  490. * @abstract Generates a short Dynamic Link URL using all set parameters.
  491. * @param completion A block to be executed upon completion of the shortening attempt. It is
  492. * guaranteed to be executed once and on the main thread.
  493. */
  494. - (void)shortenWithCompletion:(FIRDynamicLinkShortenerCompletion)completion;
  495. @end
  496. NS_ASSUME_NONNULL_END