Skip to content

Commit

Permalink
Replace domain specific with bundle identifier
Browse files Browse the repository at this point in the history
This is effective and no more hard-coded for domain i.e.
"io.wasin.potatso" as this will get replaced by bundle identifier either
that source file is in ObjC or Swift, then use code version
appropriately

Also take note that for example PacketTunnel has such hard-coded of
domain too but using above approach will change it to use its own
target's application bundle identifier i.e. "io.wasin.potatso.tunnel".

PS. Interchange your own domain name with above freely.
  • Loading branch information
haxpor committed Jan 27, 2017
1 parent 7966bed commit 91fa30e
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions PacketTunnel/ProxyManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ - (void)onSocksProxyCallback:(int)fd {
self.socksProxyPort = sock_port(fd);
self.socksProxyRunning = YES;
}else {
error = [NSError errorWithDomain:@"io.wasin.potatso" code:100 userInfo:@{NSLocalizedDescriptionKey: @"Fail to start socks proxy"}];
error = [NSError errorWithDomain:[[NSBundle mainBundle] bundleIdentifier] code:100 userInfo:@{NSLocalizedDescriptionKey: @"Fail to start socks proxy"}];
}
if (self.socksCompletion) {
self.socksCompletion(self.socksProxyPort, error);
Expand Down Expand Up @@ -142,7 +142,7 @@ - (void)onShadowsocksCallback:(int)fd {
self.shadowsocksProxyPort = sock_port(fd);
self.shadowsocksProxyRunning = YES;
}else {
error = [NSError errorWithDomain:@"io.wasin.potatso" code:100 userInfo:@{NSLocalizedDescriptionKey: @"Fail to start http proxy"}];
error = [NSError errorWithDomain:[[NSBundle mainBundle] bundleIdentifier] code:100 userInfo:@{NSLocalizedDescriptionKey: @"Fail to start http proxy"}];
}
if (self.shadowsocksCompletion) {
self.shadowsocksCompletion(self.shadowsocksProxyPort, error);
Expand Down Expand Up @@ -179,7 +179,7 @@ - (void)onHttpProxyCallback:(int)fd {
self.httpProxyPort = sock_port(fd);
self.httpProxyRunning = YES;
}else {
error = [NSError errorWithDomain:@"io.wasin.potatso" code:100 userInfo:@{NSLocalizedDescriptionKey: @"Fail to start http proxy"}];
error = [NSError errorWithDomain:[[NSBundle mainBundle] bundleIdentifier] code:100 userInfo:@{NSLocalizedDescriptionKey: @"Fail to start http proxy"}];
}
if (self.httpCompletion) {
self.httpCompletion(self.httpProxyPort, error);
Expand Down
2 changes: 1 addition & 1 deletion PacketTunnel/TunnelError.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@implementation TunnelError

+ (NSError *)errorWithMessage:(NSString *)message {
return [NSError errorWithDomain:@"io.wasin.potatso" code:100 userInfo:@{NSLocalizedDescriptionKey: message ? : @""}];
return [NSError errorWithDomain:[[NSBundle mainBundle] bundleIdentifier]code:100 userInfo:@{NSLocalizedDescriptionKey: message ? : @""}];
}

@end
16 changes: 8 additions & 8 deletions Potatso.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@
9B1F74751C3164AC0028C1A6 /* VPN.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VPN.swift; sourceTree = "<group>"; };
9B2290FE1C8E5B9600EEC901 /* DataInitializer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataInitializer.swift; sourceTree = "<group>"; };
9B2D8C891C7C3F5B00CC65B3 /* ProxyManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProxyManager.h; sourceTree = "<group>"; };
9B2D8C8A1C7C3F5B00CC65B3 /* ProxyManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProxyManager.m; sourceTree = "<group>"; };
9B2D8C8A1C7C3F5B00CC65B3 /* ProxyManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = ProxyManager.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
9B3247891CC0F1D200A3BAFF /* Importer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Importer.swift; sourceTree = "<group>"; };
9B54CC431C1C266C00DDEEBB /* UIViewControllerExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIViewControllerExtensions.swift; sourceTree = "<group>"; };
9B5C00251CBFB35C008DDE7A /* ConfigGroupCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfigGroupCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -424,7 +424,7 @@
9BC6002D1CB299DE00E5EA61 /* JSONUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSONUtils.h; sourceTree = "<group>"; };
9BC6002E1CB299DE00E5EA61 /* JSONUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSONUtils.m; sourceTree = "<group>"; };
9BC6002F1CB299DE00E5EA61 /* NSError+Helper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+Helper.h"; sourceTree = "<group>"; };
9BC600301CB299DE00E5EA61 /* NSError+Helper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSError+Helper.m"; sourceTree = "<group>"; };
9BC600301CB299DE00E5EA61 /* NSError+Helper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "NSError+Helper.m"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
9BC6FFEA1CB28B4B00E5EA61 /* PotatsoModel.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PotatsoModel.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9BC6FFEC1CB28B4B00E5EA61 /* PotatsoModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PotatsoModel.h; sourceTree = "<group>"; };
9BC6FFEE1CB28B4B00E5EA61 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -859,8 +859,8 @@
ABA819ED933DB4838AE71396 /* Pods-PacketProcessor.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PacketProcessor.release.xcconfig"; path = "Pods/Target Support Files/Pods-PacketProcessor/Pods-PacketProcessor.release.xcconfig"; sourceTree = "<group>"; };
B03E5F0D3FAB0B3302CA1A4E /* Pods_PacketTunnel.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PacketTunnel.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B803A6951D0165EA003EA9AA /* CloudViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CloudViewController.swift; sourceTree = "<group>"; };
B803A6971D02B768003EA9AA /* API.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = API.swift; sourceTree = "<group>"; };
B821B0EF1D51DD8F0061E7B9 /* KeychainUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainUtils.swift; sourceTree = "<group>"; };
B803A6971D02B768003EA9AA /* API.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = API.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
B821B0EF1D51DD8F0061E7B9 /* KeychainUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = KeychainUtils.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
B821B0F21D5334D50061E7B9 /* ActionRow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionRow.swift; sourceTree = "<group>"; };
B821B0F41D5335DA0061E7B9 /* FeedbackManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedbackManager.swift; sourceTree = "<group>"; };
B821B0F61D539CFD0061E7B9 /* SyncVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SyncVC.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -893,10 +893,10 @@
B896A83F1D548AAC009E4BF5 /* ICloudSetupOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ICloudSetupOperation.swift; sourceTree = "<group>"; };
B8A09D681D51B42B00A9A989 /* CloudKitRecord.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CloudKitRecord.swift; sourceTree = "<group>"; };
B8A09D741D51B9A900A9A989 /* AlertOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertOperation.swift; sourceTree = "<group>"; };
B8A09D751D51B9A900A9A989 /* FetchCloudChangesOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchCloudChangesOperation.swift; sourceTree = "<group>"; };
B8A09D751D51B9A900A9A989 /* FetchCloudChangesOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = FetchCloudChangesOperation.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
B8A09D771D51B9A900A9A989 /* PrepareZoneOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrepareZoneOperation.swift; sourceTree = "<group>"; };
B8A09D781D51B9A900A9A989 /* PushLocalChangesBaseOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PushLocalChangesBaseOperation.swift; sourceTree = "<group>"; };
B8A09D791D51B9A900A9A989 /* RealmCloud.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RealmCloud.swift; sourceTree = "<group>"; };
B8A09D781D51B9A900A9A989 /* PushLocalChangesBaseOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = PushLocalChangesBaseOperation.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
B8A09D791D51B9A900A9A989 /* RealmCloud.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = RealmCloud.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
B8B1E4A51D6584DC003F8530 /* User.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
B8C0FE0E1D5DF96500737454 /* PushLocalModifiedChangesOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PushLocalModifiedChangesOperation.swift; sourceTree = "<group>"; };
B8C0FE121D5DFDB500737454 /* PushLocalDeletedChangesOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PushLocalDeletedChangesOperation.swift; sourceTree = "<group>"; };
Expand All @@ -914,7 +914,7 @@
B8D8CC101D50D5CD00CE6C0D /* SyncManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SyncManager.swift; sourceTree = "<group>"; };
B8D8CC121D50D5DB00CE6C0D /* ICloudSyncService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ICloudSyncService.swift; sourceTree = "<group>"; };
B8EAC5921D40BF310046963C /* TunnelError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TunnelError.h; sourceTree = "<group>"; };
B8EAC5931D40BF310046963C /* TunnelError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TunnelError.m; sourceTree = "<group>"; };
B8EAC5931D40BF310046963C /* TunnelError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = TunnelError.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
B8F7845B1D36760D00F02FF5 /* DashboardVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DashboardVC.swift; sourceTree = "<group>"; };
B8F784651D3678B400F02FF5 /* Settings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Settings.h; sourceTree = "<group>"; };
B8F784661D3678B400F02FF5 /* Settings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Settings.m; sourceTree = "<group>"; };
Expand Down
12 changes: 6 additions & 6 deletions Potatso/Core/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ extension Alamofire.DataRequest {
let failureReason = "Data could not be serialized. Input data was nil."
//let error = Alamofire.Error.errorWithCode(.dataSerializationFailed, failureReason: failureReason)
let userInfo = [NSLocalizedFailureReasonErrorKey: failureReason]
let error = NSError(domain: "io.wasin.potatso", code: 9999, userInfo: userInfo)
let error = NSError(domain: Bundle.main.bundleIdentifier!, code: 9999, userInfo: userInfo)
logError(error, request: request, response: response)
return .failure(error)
}
Expand All @@ -170,7 +170,7 @@ extension Alamofire.DataRequest {
if let errorMessage = (result.value as AnyObject).value(forKeyPath: "error_message") as? String {
//let error = Alamofire.Error.errorWithCode(.statusCodeValidationFailed, failureReason: errorMessage)
let userInfo = [NSLocalizedFailureReasonErrorKey: errorMessage]
let error = NSError(domain: "io.wasin.potatso", code: 9999, userInfo: userInfo)
let error = NSError(domain: Bundle.main.bundleIdentifier!, code: 9999, userInfo: userInfo)
logError(error, request: request, response: response)
return .failure(error)
}
Expand All @@ -193,7 +193,7 @@ extension Alamofire.DataRequest {
let failureReason = "ObjectMapper failed to serialize response"
//let error = Alamofire.Error.errorWithCode(.dataSerializationFailed, failureReason: failureReason)
let userInfo = [NSLocalizedFailureReasonErrorKey: failureReason]
let error = NSError(domain: "io.wasin.potatso", code: 9999, userInfo: userInfo)
let error = NSError(domain: Bundle.main.bundleIdentifier!, code: 9999, userInfo: userInfo)
logError(error, request: request, response: response)
return .failure(error)
}
Expand Down Expand Up @@ -226,7 +226,7 @@ extension Alamofire.DataRequest {
let failureReason = "Data could not be serialized. Input data was nil."
//let error = Alamofire.Error.errorWithCode(.dataSerializationFailed, failureReason: failureReason)
let userInfo = [NSLocalizedFailureReasonErrorKey: failureReason]
let error = NSError(domain: "io.wasin.potatso", code: 9999, userInfo: userInfo)
let error = NSError(domain: Bundle.main.bundleIdentifier!, code: 9999, userInfo: userInfo)
logError(error, request: request, response: response)
return .failure(error)
}
Expand All @@ -237,7 +237,7 @@ extension Alamofire.DataRequest {
if let errorMessage = (result.value as AnyObject).value(forKeyPath: "error_message") as? String {
//let error = Alamofire.Error.errorWithCode(.statusCodeValidationFailed, failureReason: errorMessage)
let userInfo = [NSLocalizedFailureReasonErrorKey: errorMessage]
let error = NSError(domain: "io.wasin.potatso", code: 9999, userInfo: userInfo)
let error = NSError(domain: Bundle.main.bundleIdentifier!, code: 9999, userInfo: userInfo)
logError(error, request: request, response: response)
return .failure(error)
}
Expand All @@ -257,7 +257,7 @@ extension Alamofire.DataRequest {
let failureReason = "ObjectMapper failed to serialize response."
//let error = Alamofire.Error.errorWithCode(.dataSerializationFailed, failureReason: failureReason)
let userInfo = [NSLocalizedFailureReasonErrorKey: failureReason]
let error = NSError(domain: "io.wasin.potatso", code: 9999, userInfo: userInfo)
let error = NSError(domain: Bundle.main.bundleIdentifier!, code: 9999, userInfo: userInfo)
logError(error, request: request, response: response)
return .failure(error)
}
Expand Down
2 changes: 1 addition & 1 deletion Potatso/Sync/FetchCloudChangesOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class FetchCloudChangesOperation: PSOperations.Operation {
Implement custom logic here for handling CloudKit fetch errors.
*/
func handleCloudKitFetchError(_ error: NSError, completionHandler: @escaping (NSError!) -> ()) {
let ckErrorCode: CKError = CKError(_nsError: NSError(domain: "io.wasin.potatso", code: error.code))
let ckErrorCode: CKError = CKError(_nsError: NSError(domain: Bundle.main.bundleIdentifier!, code: error.code))

switch ckErrorCode.code {
case .zoneBusy, .requestRateLimited, .serviceUnavailable, .networkFailure, .networkUnavailable, .resultsTruncated:
Expand Down
2 changes: 1 addition & 1 deletion Potatso/Sync/PushLocalChangesBaseOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class PushLocalChangesBaseOperation: PSOperations.Operation {
Implement custom logic here for handling CloudKit push errors.
*/
func handleCloudKitPushError(_ savedRecords: [CKRecord]?, deletedRecordIDs: [CKRecordID]?, error: NSError, completionHandler: @escaping (NSError?) -> ()) {
let ckErrorCode: CKError = CKError(_nsError: NSError(domain: "io.wasin.potatso", code: error.code))
let ckErrorCode: CKError = CKError(_nsError: NSError(domain: Bundle.main.bundleIdentifier!, code: error.code))
switch ckErrorCode.code {
case .partialFailure:
resolvePushConflictsAndRetry(savedRecords, deletedRecordIDs: deletedRecordIDs, error: error, completionHandler: completionHandler)
Expand Down
4 changes: 2 additions & 2 deletions Potatso/Sync/RealmCloud.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public func resolveConflicts(_ error: NSError,
as? [CKRecordID : NSError] {

for (_, partialError) in errorDict {
let errorCode = CKError(_nsError: NSError(domain: "io.wasin.potatso", code: partialError.code))
let errorCode = CKError(_nsError: NSError(domain: Bundle.main.bundleIdentifier!, code: partialError.code))
if errorCode.code == CKError.Code.serverRecordChanged {
let userInfo = partialError.userInfo

Expand Down Expand Up @@ -153,7 +153,7 @@ public func createAlertOperation(_ error: NSError) -> AlertOperation {
"Error Code: RLMError.\(errorString) (\(error.localizedDescription))"

case CKErrorDomain:
let ckErrorCode: CKError = CKError(_nsError: NSError(domain: "io.wasin.potatso", code: error.code))
let ckErrorCode: CKError = CKError(_nsError: NSError(domain: Bundle.main.bundleIdentifier!, code: error.code))

alert.title = "Cloud Error"
alert.message =
Expand Down
2 changes: 1 addition & 1 deletion Potatso/Utils/KeychainUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
import Foundation
import KeychainAccess

let keychain = Keychain(service: "io.wasin.potatso")
let keychain = Keychain(service: Bundle.main.bundleIdentifier!)
2 changes: 1 addition & 1 deletion PotatsoBase/NSError+Helper.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@implementation NSError (Helper)

+ (NSError *)errorWithCode: (NSInteger)code description: (NSString *)description {
return [NSError errorWithDomain:@"io.wasin.potatso" code:code userInfo:@{NSLocalizedDescriptionKey: description}];
return [NSError errorWithDomain:[[NSBundle mainBundle] bundleIdentifier] code:code userInfo:@{NSLocalizedDescriptionKey: description}];
}

@end

0 comments on commit 91fa30e

Please sign in to comment.