UAUtils

@interface UAUtils : NSObject

The UAUtils object provides an interface for utility methods.

  • Get the device model name. e.g., iPhone3,1

    Declaration

    Objective-C

    + (nonnull NSString *)deviceModelName;

    Swift

    class func deviceModelName() -> String

    Return Value

    The device model name.

  • Gets the user auth header string for the provided user data.

    Declaration

    Objective-C

    + (nonnull NSString *)userAuthHeaderString:(nonnull UAUserData *)userData;

    Swift

    class func userAuthHeaderString(_ userData: UAUserData) -> String

    Parameters

    userData

    The user data.

  • Returns a basic auth header string.

    The return value takes the form of: Basic [Base64 Encoded "username:password"]

    Declaration

    Objective-C

    + (nonnull NSString *)appAuthHeaderString;

    Swift

    class func appAuthHeaderString() -> String

    Return Value

    An HTTP Basic Auth header string value for the app’s credentials.



  • Declaration

    Objective-C

    + (nonnull NSString *)pluralize:(int)count
                       singularForm:(nonnull NSString *)singular
                         pluralForm:(nonnull NSString *)plural;

    Swift

    class func pluralize(_ count: Int32, singularForm singular: String, pluralForm plural: String) -> String
  • Creates an ISO dateFormatter (UTC) with the following attributes: locale set to ‘en_US_POSIX’, timestyle set to ‘NSDateFormatterFullStyle’, date format set to ‘yyyy-MM-dd HH:mm:ss’.

    Declaration

    Objective-C

    + (nonnull NSDateFormatter *)ISODateFormatterUTC;

    Swift

    class func isoDateFormatterUTC() -> DateFormatter

    Return Value

    A DateFormatter with the default attributes.

  • Creates an ISO dateFormatter (UTC) with the following attributes: locale set to ‘en_US_POSIX’, timestyle set to ‘NSDateFormatterFullStyle’, date format set to ‘yyyy-MM-dd’T'HH:mm:ss’. The formatter returned by this method is identical to that of ISODateFormatterUTC, except that the format matches the optional T delimiter between date and time.

    Declaration

    Objective-C

    + (nonnull NSDateFormatter *)ISODateFormatterUTCWithDelimiter;

    Swift

    class func isoDateFormatterUTCWithDelimiter() -> DateFormatter

    Return Value

    A DateFormatter with the default attributes, matching the optional T delimiter.

  • Parses ISO 8601 date strings. Supports timestamps with just year all the way up to seconds with and without the optional T delimeter.

    Declaration

    Objective-C

    + (nullable NSDate *)parseISO8601DateFromString:(nonnull NSString *)timestamp;

    Swift

    class func parseISO8601Date(from timestamp: String) -> Date?

    Parameters

    timestamp

    The ISO 8601 timestamp.

    Return Value

    A parsed NSDate object, or nil if the timestamp is not a valid format.

  • Sets a file or directory at a url to not backup in iCloud or iTunes

    Declaration

    Objective-C

    + (BOOL)addSkipBackupAttributeToItemAtURL:(nonnull NSURL *)url;

    Swift

    class func addSkipBackupAttributeToItem(at url: URL) -> Bool

    Parameters

    url

    The items url

    Return Value

    YES if successful, NO otherwise

  • Returns the main window for the app. This window will be positioned underneath any other windows added and removed at runtime, by classes such a UIAlertView or UIActionSheet.

    Declaration

    Objective-C

    + (nullable UIWindow *)mainWindow;

    Swift

    class func mainWindow() -> UIWindow?

    Return Value

    The main window, or nil if the window cannot be found.

  • Returns the main window for the app. This window will be positioned underneath any other windows added and removed at runtime, by classes such a UIAlertView or UIActionSheet.

    Declaration

    Objective-C

    + (nullable UIWindow *)mainWindow:(nullable UIWindowScene *)scene;

    Swift

    class func mainWindow(_ scene: UIWindowScene?) -> UIWindow?

    Parameters

    scene

    The scene in which to find the window.

    Return Value

    The main window, or nil if the window cannot be found.

  • Returns the window containing the provided view.

    Declaration

    Objective-C

    + (nullable UIWindow *)windowForView:(nonnull UIView *)view;

    Swift

    class func window(for view: UIView) -> UIWindow?

    Parameters

    view

    The view.

    Return Value

    The window containing the view, or nil if the view is not currently displayed.

  • A utility method that grabs the top-most view controller for the main application window. May return nil if a suitable view controller cannot be found.

    Declaration

    Objective-C

    + (nullable UIViewController *)topController;

    Swift

    class func topController() -> UIViewController?

    Return Value

    The top-most view controller or nil if controller cannot be found.

  • Gets the current connection type. Possible values are cell, wifi, or none.

    Declaration

    Objective-C

    + (nonnull NSString *)connectionType;

    Swift

    class func connectionType() -> String

    Return Value

    The current connection type as a string.

  • Determine if the notification payload is a silent push (no notification elements).

    Declaration

    Objective-C

    + (BOOL)isSilentPush:(nonnull NSDictionary *)notification;

    Swift

    class func isSilentPush(_ notification: [AnyHashable : Any]) -> Bool

    Parameters

    notification

    The notification payload

    Return Value

    YES if it is a silent push, NO otherwise

  • Determine if the notification payload is an alerting push.

    Declaration

    Objective-C

    + (BOOL)isAlertingPush:(nonnull NSDictionary *)notification;

    Swift

    class func isAlertingPush(_ notification: [AnyHashable : Any]) -> Bool

    Parameters

    notification

    The notification payload

    Return Value

    YES if it is an alerting push, NO otherwise

  • A utility method that takes an array of fetch results as NSNumbers and returns the merged result

    Declaration

    Objective-C

    + (UIBackgroundFetchResult)mergeFetchResults:(nonnull NSArray *)fetchResults;

    Swift

    class func mergeFetchResults(_ fetchResults: [Any]) -> UIBackgroundFetchResult
  • A utility method that takes an APNS-provided device token and returns the decoded Airship device token

    Declaration

    Objective-C

    + (nonnull NSString *)deviceTokenStringFromDeviceToken:
        (nonnull NSData *)deviceToken;

    Swift

    class func deviceTokenString(fromDeviceToken deviceToken: Data) -> String
  • A utility method that compares two version strings and determines their order.

    Declaration

    Objective-C

    + (NSComparisonResult)compareVersion:(nonnull NSString *)version1
                               toVersion:(nonnull NSString *)version2;

    Swift

    class func compareVersion(_ version1: String, toVersion version2: String) -> ComparisonResult