Toggle navigation
Toggle navigation
This project
Loading...
Sign in
open-source
/
warply_sdk_framework
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
Manos Chorianopoulos
2022-06-17 17:12:06 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2ad278f9efba8d02d39c04572a28d2a1272da8c0
2ad278f9
1 parent
3c2c2eea
add initializeWithCallback
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
232 additions
and
2 deletions
.DS_Store
SwiftWarplyFramework/.DS_Store
SwiftWarplyFramework/Pods/Pods.xcodeproj/xcuserdata/manos.xcuserdatad/xcschemes/xcschememanagement.plist
SwiftWarplyFramework/SwiftWarplyFramework.xcodeproj/xcuserdata/manos.xcuserdatad/xcschemes/xcschememanagement.plist
SwiftWarplyFramework/SwiftWarplyFramework.xcworkspace/xcuserdata/manos.xcuserdatad/UserInterfaceState.xcuserstate
SwiftWarplyFramework/SwiftWarplyFramework/.DS_Store
SwiftWarplyFramework/SwiftWarplyFramework/MyApi.h
SwiftWarplyFramework/SwiftWarplyFramework/MyApi.m
SwiftWarplyFramework/SwiftWarplyFramework/Warply/Warply.h
SwiftWarplyFramework/SwiftWarplyFramework/Warply/Warply.m
.DS_Store
View file @
2ad278f
No preview for this file type
SwiftWarplyFramework/.DS_Store
View file @
2ad278f
No preview for this file type
SwiftWarplyFramework/Pods/Pods.xcodeproj/xcuserdata/manos.xcuserdatad/xcschemes/xcschememanagement.plist
View file @
2ad278f
...
...
@@ -7,7 +7,7 @@
<key>
Pods-SwiftWarplyFramework.xcscheme_^#shared#^_
</key>
<dict>
<key>
orderHint
</key>
<integer>
1
</integer>
<integer>
0
</integer>
</dict>
</dict>
</dict>
...
...
SwiftWarplyFramework/SwiftWarplyFramework.xcodeproj/xcuserdata/manos.xcuserdatad/xcschemes/xcschememanagement.plist
View file @
2ad278f
...
...
@@ -7,7 +7,7 @@
<key>
SwiftWarplyFramework.xcscheme_^#shared#^_
</key>
<dict>
<key>
orderHint
</key>
<integer>
0
</integer>
<integer>
1
</integer>
</dict>
</dict>
</dict>
...
...
SwiftWarplyFramework/SwiftWarplyFramework.xcworkspace/xcuserdata/manos.xcuserdatad/UserInterfaceState.xcuserstate
View file @
2ad278f
No preview for this file type
SwiftWarplyFramework/SwiftWarplyFramework/.DS_Store
View file @
2ad278f
No preview for this file type
SwiftWarplyFramework/SwiftWarplyFramework/MyApi.h
View file @
2ad278f
...
...
@@ -16,6 +16,7 @@
@property
(
nonatomic
,
weak
)
Warply
*
warply
;
-
(
void
)
initialize
:(
NSDictionary
*
)
launchOptions
uuid
:(
NSString
*
)
uuid
merchantId
:(
NSString
*
)
merchantId
lang
:(
NSString
*
)
lang
;
-
(
void
)
initializeWithCallback
:(
NSDictionary
*
)
launchOptions
uuid
:(
NSString
*
)
uuid
merchantId
:(
NSString
*
)
merchantId
lang
:(
NSString
*
)
lang
successBlock
:(
void
(
^
)(
NSDictionary
*
successBlock
))
success
failureBlock
:(
void
(
^
)(
NSError
*
error
))
failure
;
-
(
void
)
setToStage
;
-
(
void
)
setLang
:(
NSString
*
)
lang
;
-
(
void
)
getSteps
:(
void
(
^
)(
CMPedometerData
*
stepsData
))
completion
;
...
...
SwiftWarplyFramework/SwiftWarplyFramework/MyApi.m
View file @
2ad278f
...
...
@@ -51,6 +51,36 @@ CMPedometer *pedometer;
// }
}
-
(
void
)
initializeWithCallback
:(
NSDictionary
*
)
launchOptions
uuid
:(
NSString
*
)
uuid
merchantId
:(
NSString
*
)
merchantId
lang
:(
NSString
*
)
lang
successBlock
:(
void
(
^
)(
NSDictionary
*
successBlock
))
success
failureBlock
:(
void
(
^
)(
NSError
*
error
))
failure
{
#if (DEBUG == 1)
[
Warply
launchWithAppUUIDWithCallback
:
uuid
launchOptions
:
launchOptions
andSuccessBlock
:
success
andFailureBlock
:
failure
];
#else
[
Warply
launchWithAppUUIDWithCallback
:
uuid
launchOptions
:
launchOptions
andSuccessBlock
:
success
andFailureBlock
:
failure
];
#endif
[[
Warply
sharedService
].
pushManager
registerForRemoteNotifications
];
[[
Warply
sharedService
].
pushManager
resetBadge
];
MERCHANT_ID
=
merchantId
;
LANG
=
lang
;
//removal of caching
int
cacheSizeMemory
=
0
;
// 0MB
int
cacheSizeDisk
=
0
;
// 0MB
NSURLCache
*
sharedCache
=
[[
NSURLCache
alloc
]
initWithMemoryCapacity
:
cacheSizeMemory
diskCapacity
:
cacheSizeDisk
diskPath
:
@"nsurlcache"
];
[
NSURLCache
setSharedURLCache
:
sharedCache
];
// date = [NSDate date];
// if ([CMPedometer isStepCountingAvailable]) {
// pedometer = [[CMPedometer alloc] init];
// [NSTimer scheduledTimerWithTimeInterval:0.5f
// target:self
// selector:@selector(recursiveQuery)
// userInfo:nil
// repeats:YES];
// } else {
// NSLog(@"Nothing available");
//
// }
}
-
(
void
)
queryDataFrom
:(
NSDate
*
)
startDate
toDate
:(
NSDate
*
)
endDate
{
[
pedometer
queryPedometerDataFromDate
:
startDate
toDate
:
endDate
...
...
SwiftWarplyFramework/SwiftWarplyFramework/Warply/Warply.h
View file @
2ad278f
...
...
@@ -145,6 +145,7 @@ typedef enum {
empty if application launched by user.
*/
+
(
void
)
launchWithAppUUID
:(
NSString
*
)
appUUID
launchOptions
:(
NSDictionary
*
)
launchOptions
;
+
(
void
)
launchWithAppUUIDWithCallback
:(
NSString
*
)
appUUID
launchOptions
:(
NSDictionary
*
)
launchOptions
andSuccessBlock
:(
void
(
^
)(
NSDictionary
*
))
success
andFailureBlock
:(
void
(
^
)(
NSError
*
error
))
failure
;
/*!
@abstract Launching the Warply service.
...
...
@@ -157,6 +158,7 @@ typedef enum {
@param customPushDelegate an class conforming to the WLCustomPushDelegate protocol responsible for handling the push notification.
*/
+
(
void
)
launchWithAppUUID
:(
NSString
*
)
appUUID
launchOptions
:(
NSDictionary
*
)
launchOptions
customPushHandler
:(
id
<
WLCustomPushHandler
>
)
customPushHandler
;
+
(
void
)
launchWithAppUUIDWithCallback
:(
NSString
*
)
appUUID
launchOptions
:(
NSDictionary
*
)
launchOptions
customPushHandler
:(
id
<
WLCustomPushHandler
>
)
customPushHandler
andSuccessBlock
:(
void
(
^
)(
NSDictionary
*
))
success
andFailureBlock
:(
void
(
^
)(
NSError
*
error
))
failure
;
/*!
@abstract Launching the Warply service.
...
...
@@ -170,6 +172,7 @@ typedef enum {
@param baseUrl: A NSString parameter for defining the base url.
*/
+
(
void
)
launchWithAppUUID
:(
NSString
*
)
appUUID
launchOptions
:(
NSDictionary
*
)
launchOptions
customPushDelegate
:(
id
<
WLCustomPushHandler
>
)
customPushDelegate
serverBaseUrl
:(
NSString
*
)
baseUrl
;
+
(
void
)
launchWithAppUUIDWithCallback
:(
NSString
*
)
appUUID
launchOptions
:(
NSDictionary
*
)
launchOptions
customPushDelegate
:(
id
<
WLCustomPushHandler
>
)
customPushDelegate
serverBaseUrl
:(
NSString
*
)
baseUrl
andSuccessBlock
:(
void
(
^
)(
NSDictionary
*
))
success
andFailureBlock
:(
void
(
^
)(
NSError
*
error
))
failure
;
/*!
...
...
SwiftWarplyFramework/SwiftWarplyFramework/Warply/Warply.m
View file @
2ad278f
...
...
@@ -147,17 +147,78 @@ typedef void (^FailureResponse)(NSURLSessionDataTask * _Nullable task, NSError *
}
///////////////////////////////////////////////////////////////////////////////
+
(
void
)
launchWithAppUUIDWithCallback
:
(
NSString
*
)
appUUID
launchOptions
:
(
NSDictionary
*
)
launchOptions
customPushDelegate
:
(
id
<
WLCustomPushHandler
>
)
customPushDelegate
serverBaseUrl
:
(
NSString
*
)
url
andSuccessBlock
:
(
void
(
^
)(
NSDictionary
*
))
success
andFailureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
{
//Launch Once
if
(
_sharedService
!=
nil
)
{
// TODO: Maybe add failure callback here? - msg: "already launched"
return
;
}
dispatch_once
(
&
pred
,
^
{
NSString
*
mode
=
@"Production"
;
#if (DEBUG == 1)
mode
=
@"Debug"
;
#endif
//Load Configuration
NSAssert
(
!
[
appUUID
containsString
:
@"Insert your"
]
&&
[
appUUID
length
]
>
0
,
@"WARPLY: You have not inserted your %@ app UUID!"
,
mode
);
_sharedService
=
[[
Warply
alloc
]
initWithApplicationUUID
:
appUUID
];
_sharedService
.
baseURL
=
url
;
if
([
_sharedService
isRegistrationValid
]
==
NO
)
{
[
_sharedService
.
pendingOperationsQueue
setSuspended
:
YES
];
[
_sharedService
registrationWithSuccessBlock2
:
success
andFailureBlock
:
failure
];
}
else
{
NSDictionary
*
successCallback
=
[[
NSMutableDictionary
alloc
]
init
];
[
successCallback
setValue
:
@1
forKey
:
@"status"
];
[
successCallback
setValue
:
@"success"
forKey
:
@"msg"
];
success
(
successCallback
);
}
if
(
customPushDelegate
!=
nil
)
{
_sharedService
.
pushManager
.
customPushHanlder
=
customPushDelegate
;
}
[
_sharedService
.
pushManager
didFinishLaunchingWithOptions
:
launchOptions
];
[
_sharedService
networkReachabilityReporting
];
[
WLAnalyticsManager
logAppDidFinishLauchingEvent
];
[
WLUserManager
sendUUIDS
];
[
_sharedService
sendEventsIfNeeded
];
[
_sharedService
getLocationPoint
];
});
}
///////////////////////////////////////////////////////////////////////////////
+
(
void
)
launchWithAppUUID
:
(
NSString
*
)
appUUID
launchOptions
:
(
NSDictionary
*
)
launchOptions
{
[
self
launchWithAppUUID
:
appUUID
launchOptions
:
launchOptions
customPushHandler
:
nil
];
}
///////////////////////////////////////////////////////////////////////////////
+
(
void
)
launchWithAppUUIDWithCallback
:
(
NSString
*
)
appUUID
launchOptions
:
(
NSDictionary
*
)
launchOptions
andSuccessBlock
:
(
void
(
^
)(
NSDictionary
*
))
success
andFailureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
{
[
self
launchWithAppUUIDWithCallback
:
appUUID
launchOptions
:
launchOptions
customPushHandler
:
nil
andSuccessBlock
:
success
andFailureBlock
:
failure
];
}
///////////////////////////////////////////////////////////////////////////////
+
(
void
)
launchWithAppUUID
:
(
NSString
*
)
appUUID
launchOptions
:
(
NSDictionary
*
)
launchOptions
customPushHandler
:
(
id
<
WLCustomPushHandler
>
)
customPushDelegate
{
[
self
launchWithAppUUID
:
appUUID
launchOptions
:
launchOptions
customPushDelegate
:
customPushDelegate
serverBaseUrl
:
WARP_PRODUCTION_BASE_URL
];
}
///////////////////////////////////////////////////////////////////////////////
+
(
void
)
launchWithAppUUIDWithCallback
:
(
NSString
*
)
appUUID
launchOptions
:
(
NSDictionary
*
)
launchOptions
customPushHandler
:
(
id
<
WLCustomPushHandler
>
)
customPushDelegate
andSuccessBlock
:
(
void
(
^
)(
NSDictionary
*
))
success
andFailureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
{
[
self
launchWithAppUUIDWithCallback
:
appUUID
launchOptions
:
launchOptions
customPushDelegate
:
customPushDelegate
serverBaseUrl
:
WARP_PRODUCTION_BASE_URL
andSuccessBlock
:
success
andFailureBlock
:
failure
];
}
#pragma mark - Initialization
///////////////////////////////////////////////////////////////////////////////
-
(
id
)
initWithApplicationUUID
:
(
NSString
*
)
appUUID
...
...
@@ -4551,6 +4612,141 @@ CGFloat DistanceBetweenTwoPoints(CGPoint point1,CGPoint point2)
// [operation start];
}
///////////////////////////////////////////////////////////////////////////////
-
(
void
)
registrationWithSuccessBlock2
:
(
void
(
^
)(
NSDictionary
*
successBlock
))
success
andFailureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
{
if
(
_waitingForRegistration
==
YES
)
return
;
_waitingForRegistration
=
YES
;
NSString
*
urlString
=
[
NSString
stringWithFormat
:
@"%@/api/mobile/v2/%@/register/"
,
_baseURL
,
_appUUID
];
// NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:100];
// [request setAllHTTPHeaderFields:@{@"Accept-Encoding": @"gzip",
// @"Accept": @"application/json",
// @"User-Agent": @"gzip",
// @"loyalty-bundle-id": [NSString stringWithFormat:@"ios:%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"]]}];
[
_httpClient
.
requestSerializer
setValue
:
@"gzip"
forHTTPHeaderField
:
@"Accept-Encoding"
];
[
_httpClient
.
requestSerializer
setValue
:
@"application/json"
forHTTPHeaderField
:
@"Accept"
];
[
_httpClient
.
requestSerializer
setValue
:
@"gzip"
forHTTPHeaderField
:
@"User-Agent"
];
[
_httpClient
.
requestSerializer
setValue
:[
NSString
stringWithFormat
:
@"ios:%@"
,
[[
NSBundle
mainBundle
]
objectForInfoDictionaryKey
:
@"CFBundleIdentifier"
]]
forHTTPHeaderField
:
@"loyalty-bundle-id"
];
//HTTP Method
// [request setHTTPMethod:@"GET"];
/*AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)*/
////////////////////////////!!!!!
// AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]
// initWithRequest:request];
// operation.responseSerializer = [AFJSONResponseSerializer serializer];
// [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation
// , id JSON)
////////////////////////////
SuccessResponse
successResponse
=
^
(
NSURLSessionDataTask
*
_Nonnull
task
,
id
_Nullable
JSON
)
{
if
([
JSON
objectForKey
:
@"status"
])
{
WLLOG
(
@"************* WARP Registration ********************"
);
WLLOG
(
@"[WARP Registration] URL: %@"
,
urlString
);
NSData
*
jsonData
=
[
NSJSONSerialization
dataWithJSONObject
:
JSON
options
:
NSJSONWritingPrettyPrinted
error
:
NULL
];
NSString
*
jsonResponseString
=
[[
NSString
alloc
]
initWithData
:
jsonData
encoding
:
NSUTF8StringEncoding
];
WLLOG
(
@"[WARP Registration] Response:%@"
,
jsonResponseString
);
WLLOG
(
@"****************************************************"
);
_waitingForRegistration
=
NO
;
int
status
=
[[
JSON
valueForKey
:
@"status"
]
intValue
];
if
(
status
!=
WLResultCodesSuccess
)
{
[
_pendingOperationsQueue
setSuspended
:
!
[
self
isRegistrationValid
]];
if
(
failure
)
{
NSDictionary
*
eDict
=
@{
NSLocalizedDescriptionKey
:
WLResultCodesDescriptions
[(
status
-
1
)]};
NSError
*
warplyError
=
[
NSError
errorWithDomain
:
WARP_ERROR_DOMAIN
code
:
status
userInfo
:
eDict
];
failure
(
warplyError
);
}
return
;
}
NSDictionary
*
context
=
[
JSON
valueForKey
:
@"context"
];
self
.
apiKey
=
[
context
valueForKey
:
@"api_key"
];
self
.
webId
=
[
context
valueForKey
:
@"web_id"
];
[
WLKeychain
setString
:[[[
UIDevice
currentDevice
]
identifierForVendor
]
UUIDString
]
forKey
:
@"old_identifier_for_vendor"
];
[
_pendingOperationsQueue
setSuspended
:
!
[
self
isRegistrationValid
]];
if
(
success
)
{
NSDictionary
*
successCallback
=
[[
NSMutableDictionary
alloc
]
init
];
[
successCallback
setValue
:
@1
forKey
:
@"status"
];
[
successCallback
setValue
:
@"success"
forKey
:
@"msg"
];
success
(
successCallback
);
}
}
else
{
NSError
*
error
=
[
NSError
errorWithDomain
:
WARP_ERROR_DOMAIN
code
:
1026
userInfo
:
@{
NSLocalizedDescriptionKey
:
NSLocalizedString
(
@"Empry response"
,
@"Warply"
)}];
if
(
failure
)
{
failure
(
error
);
}
}
};
//failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON)
///////////////!!!!!
// failure:^(AFHTTPRequestOperation *operation, NSError *error)
///////////////
FailureResponse
failureResponse
=
^
(
NSURLSessionDataTask
*
_Nullable
task
,
NSError
*
_Nonnull
error
)
{
WLLOG
(
@"************* WARP Registration ********************"
);
WLLOG
(
@"[WARP Registration] Error: %@"
,
[
error
description
]);
WLLOG
(
@"****************************************************"
);
_waitingForRegistration
=
NO
;
[
_pendingOperationsQueue
setSuspended
:
!
[
self
isRegistrationValid
]];
if
(
failure
)
{
failure
(
error
);
}
};
_httpClient
.
responseSerializer
=
[
AFJSONResponseSerializer
serializer
];
_httpClient
.
requestSerializer
=
[
AFJSONRequestSerializer
serializer
];
// NSDictionary *context = [NSDictionary dictionaryWithObject:[[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString] forKey:];
// NSData *parameters = [NSJSONSerialization dataWithJSONObject:context options:0 error:NULL];
NSString
*
old_identifier_for_vendor
;
if
([
WLKeychain
getStringForKey
:
@"old_identifier_for_vendor"
])
{
old_identifier_for_vendor
=
[
WLKeychain
getStringForKey
:
@"old_identifier_for_vendor"
];
}
else
{
old_identifier_for_vendor
=
[[[
UIDevice
currentDevice
]
identifierForVendor
]
UUIDString
];
}
NSDictionary
*
parameters
=
@{
@"advertising_identifier"
:
[[
ASIdentifierManager
sharedManager
].
advertisingIdentifier
UUIDString
],
@"old_identifier_for_vendor"
:
old_identifier_for_vendor
,
@"new_identifier_for_vendor"
:
[[[
UIDevice
currentDevice
]
identifierForVendor
]
UUIDString
],
@"unique-device-id"
:
[[[
UIDevice
currentDevice
]
identifierForVendor
]
UUIDString
],
@"vendor"
:
@"apple"
,
@"platform"
:
@"ios"
,
@"os_version"
:
[[
UIDevice
currentDevice
]
systemVersion
],
@"channel"
:
@"mobile"
};
// NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:0 error:NULL];
[
_httpClient
POST
:
urlString
parameters
:
parameters
progress
:
nil
success
:
successResponse
failure
:
failureResponse
];
// [_httpClient GET:urlString parameters:nil progress:nil success:successResponse failure:failureResponse];
// /*[operation setAuthenticationChallengeBlock:^(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge) {
// [[challenge sender] continueWithoutCredentialForAuthenticationChallenge:challenge];
// }];*/
// ////////////////!!!!!
// [operation setWillSendRequestForAuthenticationChallengeBlock:^(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge)
// {
// [[challenge sender] continueWithoutCredentialForAuthenticationChallenge:challenge];
// }];
// ////////////////
//
// [operation start];
}
///////////////////////////////////////////////////////////////////////////////
-
(
void
)
registration
{
...
...
Please
register
or
login
to post a comment