Skip to content

Commit

Permalink
Merge pull request #24 from blueshift-labs/crash_fix
Browse files Browse the repository at this point in the history
Crash fix
  • Loading branch information
anwarshahas authored May 25, 2017
2 parents 9d20605 + 59d2417 commit c039c62
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 17 deletions.
4 changes: 2 additions & 2 deletions BlueShift-iOS-SDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "BlueShift-iOS-SDK"
s.version = "0.1.3"
s.version = "0.1.4"
s.summary = "A short description of BlueShift-iOS-SDK."

s.description = <<-DESC
Expand Down Expand Up @@ -78,7 +78,7 @@ Pod::Spec.new do |s|
# Supports git, hg, bzr, svn and HTTP.
#

s.source = { :git => "https://github.com/blueshift-labs/BlueShift-iOS-SDK.git", :tag => "0.1.3" }
s.source = { :git => "https://github.com/blueshift-labs/BlueShift-iOS-SDK.git", :tag => "0.1.4" }


# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
Expand Down
4 changes: 3 additions & 1 deletion BlueShift-iOS-SDK/BatchEventEntity.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ + (NSArray *)fetchBatchesFromCoreData {
[fetchRequest setPredicate:nextRetryTimeStampLessThanCurrentTimePredicate];
NSError *error;
@try {
results = [context executeFetchRequest:fetchRequest error:&error];
if(context && [context isKindOfClass:[NSManagedObjectContext class]]) {
results = [context executeFetchRequest:fetchRequest error:&error];
}
}
@catch (NSException *exception) {
NSLog(@"Caught exception %@", exception);
Expand Down
7 changes: 5 additions & 2 deletions BlueShift-iOS-SDK/BlueShiftAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,6 @@ - (void)applicationDidBecomeActive:(UIApplication *)application {
}

- (void)appDidEnterBackground:(UIApplication *)application {
[self.oldDelegate applicationWillTerminate:application];

if([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)])
{
__block UIBackgroundTaskIdentifier background_task;
Expand All @@ -782,6 +780,11 @@ - (void)appDidEnterBackground:(UIApplication *)application {


- (void)applicationDidEnterBackground:(UIApplication *)application {
if (self.oldDelegate) {
if([self.oldDelegate respondsToSelector:@selector(applicationDidEnterBackground:)]) {
[self.oldDelegate applicationDidEnterBackground:application];
}
}
[self appDidEnterBackground:application];
}

Expand Down
23 changes: 17 additions & 6 deletions BlueShift-iOS-SDK/BlueShiftHttpRequestBatchUpload.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ + (void)createBatches {
if(requestOperation.parameters != nil) {
[paramsArray addObject:requestOperation.parameters];
}
[context deleteObject:operationEntityToBeExecuted];
NSError *saveError = nil;
@try {
[context save:&saveError];
if(context && [context isKindOfClass:[NSManagedObjectContext class]]) {
[context deleteObject:operationEntityToBeExecuted];
}
if(context && [context isKindOfClass:[NSManagedObjectContext class]]) {
[context save:&saveError];
}
}
@catch (NSException *exception) {
NSLog(@"Caught exception %@", exception);
Expand Down Expand Up @@ -88,7 +92,7 @@ + (void)uploadBatchAtIndex:(int)index fromBatches:(NSArray *)batches {
if(index == batches.count) {
return;
} else {
BatchEventEntity *batchEvent = [batches objectAtIndex:index];
BatchEventEntity *batchEvent = [batches objectAtIndex:index];
[self processRequestsInQueue:batchEvent completetionHandler:^(BOOL status) {
[self uploadBatchAtIndex:index+1 fromBatches:batches];
}];
Expand Down Expand Up @@ -128,7 +132,9 @@ + (void) processRequestsInQueue:(BatchEventEntity *)batchEvent completetionHandl
BOOL deletedStatus;

@try {
deletedStatus = [context save:&saveError];
if(context && [context isKindOfClass:[NSManagedObjectContext class]]) {
deletedStatus = [context save:&saveError];
}
}
@catch (NSException *exception) {
NSLog(@"Caught exception %@", exception);
Expand All @@ -149,7 +155,9 @@ + (void) processRequestsInQueue:(BatchEventEntity *)batchEvent completetionHandl
BOOL deletedStatus;

@try {
deletedStatus = [context save:&saveError];
if(context && [context isKindOfClass:[NSManagedObjectContext class]]) {
deletedStatus = [context save:&saveError];
}
}
@catch (NSException *exception) {
NSLog(@"Caught exception %@", exception);
Expand Down Expand Up @@ -201,7 +209,10 @@ + (void)performRequestOperation:(BlueShiftBatchRequestOperation *)requestOperati
NSString *url = [NSString stringWithFormat:@"%@%@", kBaseURL, kBatchUploadURL];

NSMutableArray *parametersArray = (NSMutableArray*)requestOperation.paramsArray;

if ((!parametersArray) || (parametersArray.count == 0)){
handler(YES);
return;
}
NSDictionary *paramsDictionary = @{@"events": parametersArray};
// perform executions based on the request operation http method ...

Expand Down
12 changes: 9 additions & 3 deletions BlueShift-iOS-SDK/BlueShiftRequestQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ + (void)processRequestsInQueue {
BOOL deletedStatus;

@try {
deletedStatus = [context save:&saveError];
if(context && [context isKindOfClass:[NSManagedObjectContext class]]) {
deletedStatus = [context save:&saveError];
}
}
@catch (NSException *exception) {
NSLog(@"Caught exception %@", exception);
Expand Down Expand Up @@ -179,7 +181,9 @@ + (void)processRequestsInQueue {
BOOL deletedStatus;

@try {
deletedStatus = [context save:&saveError];
if(context && [context isKindOfClass:[NSManagedObjectContext class]]) {
deletedStatus = [context save:&saveError];
}
}
@catch (NSException *exception) {
NSLog(@"Caught exception %@", exception);
Expand Down Expand Up @@ -214,7 +218,9 @@ + (void)processRequestsInQueue {
BOOL deletedStatus;

@try {
deletedStatus = [context save:&saveError];
if(context && [context isKindOfClass:[NSManagedObjectContext class]]) {
deletedStatus = [context save:&saveError];
}
}
@catch (NSException *exception) {
NSLog(@"Caught exception %@", exception);
Expand Down
8 changes: 6 additions & 2 deletions BlueShift-iOS-SDK/HttpRequestOperationEntity.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ + (HttpRequestOperationEntity *)fetchFirstRecordFromCoreData {
[fetchRequest setFetchLimit:1];
NSError *error;
@try {
results = [context executeFetchRequest:fetchRequest error:&error];
if(context && [context isKindOfClass:[NSManagedObjectContext class]]) {
results = [context executeFetchRequest:fetchRequest error:&error];
}
}
@catch (NSException *exception) {
NSLog(@"Caught exception %@", exception);
Expand Down Expand Up @@ -115,7 +117,9 @@ + (NSArray *)fetchBatchWiseRecordFromCoreData {
NSError *error;

@try {
results = [context executeFetchRequest:fetchRequest error:&error];
if(context && [context isKindOfClass:[NSManagedObjectContext class]]) {
results = [context executeFetchRequest:fetchRequest error:&error];
}
}
@catch (NSException *exception) {
NSLog(@"Caught exception %@", exception);
Expand Down
2 changes: 1 addition & 1 deletion BlueShift-iOS-SDK/SDKVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
#ifndef SDKVersion_h
#define SDKVersion_h

#define kSDKVersionNumber @"0.1.3"
#define kSDKVersionNumber @"0.1.4"

#endif /* SDKVersion_h */

0 comments on commit c039c62

Please sign in to comment.