2019-05-30 17:10:50 -07:00
//
// NSError + ALTServerError . m
// AltStore
//
// Created by Riley Testut on 5 / 30 / 19.
// Copyright © 2019 Riley Testut . All rights reserved .
//
# import "NSError+ALTServerError.h"
NSErrorDomain const AltServerErrorDomain = @ "com.rileytestut.AltServer" ;
2019-06-18 16:37:54 -07:00
NSErrorDomain const AltServerInstallationErrorDomain = @ "com.rileytestut.AltServer.Installation" ;
2019-05-30 17:10:50 -07:00
2020-03-05 14:49:21 -08:00
NSErrorUserInfoKey const ALTUnderlyingErrorCodeErrorKey = @ "underlyingErrorCode" ;
NSErrorUserInfoKey const ALTProvisioningProfileBundleIDErrorKey = @ "bundleIdentifier" ;
2019-05-30 17:10:50 -07:00
@ implementation NSError ( ALTServerError )
2019-06-18 16:37:54 -07:00
+ ( void ) load
{
[ NSError setUserInfoValueProviderForDomain : AltServerErrorDomain provider : ^ id _Nullable ( NSError * _Nonnull error , NSErrorUserInfoKey _Nonnull userInfoKey ) {
2020-03-11 13:35:14 -07:00
if ( [ userInfoKey isEqualToString : NSLocalizedFailureReasonErrorKey ] )
2019-06-18 16:37:54 -07:00
{
2020-05-11 14:33:53 -07:00
return [ error altserver_localizedFailureReason ] ;
2020-03-11 13:35:14 -07:00
}
if ( [ userInfoKey isEqualToString : NSLocalizedRecoverySuggestionErrorKey ] )
{
2020-05-11 14:33:53 -07:00
return [ error altserver_localizedRecoverySuggestion ] ;
2019-06-18 16:37:54 -07:00
}
return nil ;
} ] ;
}
2020-05-11 14:33:53 -07:00
- ( nullable NSString * ) altserver_localizedFailureReason
2019-06-18 16:37:54 -07:00
{
switch ( ( ALTServerError ) self . code )
{
2020-03-11 13:35:14 -07:00
case ALTServerErrorUnderlyingError :
{
NSString * underlyingErrorCode = self . userInfo [ ALTUnderlyingErrorCodeErrorKey ] ;
if ( underlyingErrorCode = = nil )
{
return NSLocalizedString ( @ "An unknown error occured." , @ "" ) ;
}
return [ NSString stringWithFormat : NSLocalizedString ( @ "Error code: %@" , @ "" ) , underlyingErrorCode ] ;
}
2019-06-18 16:37:54 -07:00
case ALTServerErrorUnknown :
return NSLocalizedString ( @ "An unknown error occured." , @ "" ) ;
case ALTServerErrorConnectionFailed :
2020-05-21 22:06:18 -07:00
# if TARGET_OS _OSX
return NSLocalizedString ( @ "Could not connect to device." , @ "" ) ;
# else
2019-06-18 16:37:54 -07:00
return NSLocalizedString ( @ "Could not connect to AltServer." , @ "" ) ;
2020-05-21 22:06:18 -07:00
# endif
2019-06-18 16:37:54 -07:00
case ALTServerErrorLostConnection :
return NSLocalizedString ( @ "Lost connection to AltServer." , @ "" ) ;
case ALTServerErrorDeviceNotFound :
2019-09-03 21:59:54 -07:00
return NSLocalizedString ( @ "AltServer could not find this device." , @ "" ) ;
2019-06-18 16:37:54 -07:00
case ALTServerErrorDeviceWriteFailed :
2019-09-03 21:59:54 -07:00
return NSLocalizedString ( @ "Failed to write app data to device." , @ "" ) ;
2019-06-18 16:37:54 -07:00
case ALTServerErrorInvalidRequest :
return NSLocalizedString ( @ "AltServer received an invalid request." , @ "" ) ;
case ALTServerErrorInvalidResponse :
return NSLocalizedString ( @ "AltServer sent an invalid response." , @ "" ) ;
case ALTServerErrorInvalidApp :
return NSLocalizedString ( @ "The app is invalid." , @ "" ) ;
case ALTServerErrorInstallationFailed :
return NSLocalizedString ( @ "An error occured while installing the app." , @ "" ) ;
case ALTServerErrorMaximumFreeAppLimitReached :
2020-03-11 13:35:14 -07:00
return NSLocalizedString ( @ "Cannot activate more than 3 apps and app extensions." , @ "" ) ;
2019-09-13 14:25:26 -07:00
case ALTServerErrorUnsupportediOSVersion :
return NSLocalizedString ( @ "Your device must be running iOS 12.2 or later to install AltStore." , @ "" ) ;
2019-11-18 14:49:17 -08:00
case ALTServerErrorUnknownRequest :
return NSLocalizedString ( @ "AltServer does not support this request." , @ "" ) ;
case ALTServerErrorUnknownResponse :
return NSLocalizedString ( @ "Received an unknown response from AltServer." , @ "" ) ;
case ALTServerErrorInvalidAnisetteData :
return NSLocalizedString ( @ "Invalid anisette data." , @ "" ) ;
case ALTServerErrorPluginNotFound :
2020-03-11 13:35:14 -07:00
return NSLocalizedString ( @ "Could not connect to Mail plug-in." , @ "" ) ;
case ALTServerErrorProfileNotFound :
return [ self profileErrorLocalizedDescriptionWithBaseDescription : NSLocalizedString ( @ "Could not find profile" , "" ) ] ;
2020-05-14 10:29:06 -07:00
case ALTServerErrorAppDeletionFailed :
return NSLocalizedString ( @ "An error occured while removing the app." , @ "" ) ;
2020-03-11 13:35:14 -07:00
}
}
2020-05-11 14:33:53 -07:00
- ( nullable NSString * ) altserver_localizedRecoverySuggestion
2020-03-11 13:35:14 -07:00
{
switch ( ( ALTServerError ) self . code )
{
case ALTServerErrorConnectionFailed :
case ALTServerErrorDeviceNotFound :
2020-05-21 22:06:18 -07:00
return NSLocalizedString ( @ "Make sure you have trusted this device with your computer and WiFi sync is enabled." , @ "" ) ;
2020-03-05 14:49:21 -08:00
2020-03-11 13:35:14 -07:00
case ALTServerErrorPluginNotFound :
return NSLocalizedString ( @ "Make sure Mail is running and the plug-in is enabled in Mail's preferences." , @ "" ) ;
2020-03-05 14:49:21 -08:00
2020-05-21 21:00:05 -07:00
case ALTServerErrorMaximumFreeAppLimitReached :
return NSLocalizedString ( @ "Make sure “Offload Unused Apps” is disabled in Settings > iTunes & App Stores, then install or delete all offloaded apps." , @ "" ) ;
2020-03-11 13:35:14 -07:00
default :
return nil ;
2019-06-18 16:37:54 -07:00
}
}
2020-03-05 14:49:21 -08:00
2020-03-11 13:35:14 -07:00
- ( NSString * ) profileErrorLocalizedDescriptionWithBaseDescription : ( NSString * ) baseDescription
2020-03-05 14:49:21 -08:00
{
2020-03-11 13:35:14 -07:00
NSString * localizedDescription = nil ;
2020-03-05 14:49:21 -08:00
NSString * bundleID = self . userInfo [ ALTProvisioningProfileBundleIDErrorKey ] ;
if ( bundleID )
{
2020-03-11 13:35:14 -07:00
localizedDescription = [ NSString stringWithFormat : @ "%@ “%@”" , baseDescription , bundleID ] ;
2020-03-05 14:49:21 -08:00
}
else
{
2020-03-11 13:35:14 -07:00
localizedDescription = [ NSString stringWithFormat : @ "%@." , baseDescription ] ;
2020-03-05 14:49:21 -08:00
}
return localizedDescription ;
}
2019-06-18 16:37:54 -07:00
2019-05-30 17:10:50 -07:00
@ end