Skip to content

Commit d8e41b2

Browse files
committed
Fixes to example app and added simple retry logic to NativePusher
1 parent d5c2eb6 commit d8e41b2

File tree

5 files changed

+51
-5
lines changed

5 files changed

+51
-5
lines changed

Example/Images.xcassets/AppIcon.appiconset/Contents.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
"scale" : "3x"
2222
},
2323
{
24-
"idiom" : "iphone",
2524
"size" : "60x60",
25+
"idiom" : "iphone",
26+
"filename" : "pusherlogo.png",
2627
"scale" : "2x"
2728
},
2829
{
Loading

Example/LaunchScreen.xib

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
3+
<dependencies>
4+
<deployment identifier="iOS"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
6+
</dependencies>
7+
<objects>
8+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
9+
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
10+
<view contentMode="scaleToFill" id="iN0-l3-epB">
11+
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
12+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
13+
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
14+
</view>
15+
</objects>
16+
</document>

Source/NativePusher.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class NativePusher {
2222
private let CLIENT_API_V1_ENDPOINT = "https://nativepushclient-cluster1.pusher.com/client_api/v1"
2323

2424
private let URLSession = NSURLSession.sharedSession()
25+
private var failedNativeServiceRequests: Int = 0
26+
private let maxFailedRequestAttempts: Int = 6
2527

2628
/**
2729
Identifies a Pusher app.
@@ -201,11 +203,29 @@ public class NativePusher {
201203
request,
202204
completionHandler: { data, response, error in
203205
guard let httpResponse = response as? NSHTTPURLResponse
204-
where (200 <= httpResponse.statusCode && httpResponse.statusCode < 300)
206+
where (200 <= httpResponse.statusCode && httpResponse.statusCode < 300) ||
207+
error == nil
205208
else {
206-
print("Bad response from server when trying to modify subscription to interest " + interest)
209+
self.outbox.insert((interest, change), atIndex: 0)
210+
211+
if error != nil {
212+
print("Error when trying to modify subscription to interest: \(error?.localizedDescription)")
213+
} else {
214+
print("Bad response from server when trying to modify subscription to interest " + interest)
215+
}
216+
self.failedNativeServiceRequests += 1
217+
218+
if (self.failedNativeServiceRequests < self.maxFailedRequestAttempts) {
219+
callback()
220+
} else {
221+
print("Max number of failed native service requests reached")
222+
}
207223
return
208224
}
225+
226+
// Reset number of failed requests to 0 upon success
227+
self.failedNativeServiceRequests = 0
228+
209229
callback()
210230
}
211231
)

iOS Example.xcodeproj/project.pbxproj

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
33831CC31A9CFCDB00B124F1 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33831CBF1A9CFCDB00B124F1 /* Images.xcassets */; };
1212
33831CC41A9CFCDB00B124F1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 33831CC01A9CFCDB00B124F1 /* Main.storyboard */; };
1313
33831CC51A9CFCDB00B124F1 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33831CC11A9CFCDB00B124F1 /* ViewController.swift */; };
14-
33C69F161D26BEE100ABB47A /* PusherSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 33C69F111D26BEB100ABB47A /* PusherSwift.framework */; };
1514
33C69F181D26C21600ABB47A /* PusherSwift.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 33C69F111D26BEB100ABB47A /* PusherSwift.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
15+
33D9E9191D34030700015EF2 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 331187BD1D2FE89500562354 /* LaunchScreen.xib */; };
1616
/* End PBXBuildFile section */
1717

1818
/* Begin PBXCopyFilesBuildPhase section */
@@ -32,6 +32,7 @@
3232
/* Begin PBXFileReference section */
3333
21AFCABFD6461F6288FAA7A5 /* Pods_iOS_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_iOS_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3434
2EB04428B64860E705E7675C /* Pods-iOS Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-iOS Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-iOS Example/Pods-iOS Example.release.xcconfig"; sourceTree = "<group>"; };
35+
331187BD1D2FE89500562354 /* LaunchScreen.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = LaunchScreen.xib; path = Example/LaunchScreen.xib; sourceTree = SOURCE_ROOT; };
3536
33831C5E1A9CEEE900B124F1 /* iOS Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "iOS Example.app"; sourceTree = BUILT_PRODUCTS_DIR; };
3637
33831CBC1A9CFCD000B124F1 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Example/Info.plist; sourceTree = SOURCE_ROOT; };
3738
33831CBE1A9CFCDB00B124F1 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AppDelegate.swift; path = Example/AppDelegate.swift; sourceTree = SOURCE_ROOT; };
@@ -78,6 +79,7 @@
7879
33831CC11A9CFCDB00B124F1 /* ViewController.swift */,
7980
33831CBF1A9CFCDB00B124F1 /* Images.xcassets */,
8081
33831CC01A9CFCDB00B124F1 /* Main.storyboard */,
82+
331187BD1D2FE89500562354 /* LaunchScreen.xib */,
8183
33831C611A9CEEE900B124F1 /* Supporting Files */,
8284
);
8385
name = Example;
@@ -95,7 +97,6 @@
9597
4102BF433CEEFDB30CDD25C0 /* Pods */ = {
9698
isa = PBXGroup;
9799
children = (
98-
63B4963D1F9188B612AE6FB6 /* Pods-iOS Example.debug.xcconfig */,
99100
2EB04428B64860E705E7675C /* Pods-iOS Example.release.xcconfig */,
100101
);
101102
name = Pods;
@@ -144,6 +145,11 @@
144145
33831C5D1A9CEEE900B124F1 = {
145146
CreatedOnToolsVersion = 6.3;
146147
DevelopmentTeam = 2YKMTT96X8;
148+
SystemCapabilities = {
149+
com.apple.Push = {
150+
enabled = 1;
151+
};
152+
};
147153
};
148154
};
149155
};
@@ -170,6 +176,7 @@
170176
isa = PBXResourcesBuildPhase;
171177
buildActionMask = 2147483647;
172178
files = (
179+
33D9E9191D34030700015EF2 /* LaunchScreen.xib in Resources */,
173180
33831CC41A9CFCDB00B124F1 /* Main.storyboard in Resources */,
174181
33831CC31A9CFCDB00B124F1 /* Images.xcassets in Resources */,
175182
);
@@ -288,6 +295,7 @@
288295
PRODUCT_NAME = "$(TARGET_NAME)";
289296
PROVISIONING_PROFILE = "";
290297
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
298+
TARGETED_DEVICE_FAMILY = 1;
291299
};
292300
name = Debug;
293301
};
@@ -308,6 +316,7 @@
308316
PRODUCT_NAME = "$(TARGET_NAME)";
309317
PROVISIONING_PROFILE = "";
310318
SWIFT_OPTIMIZATION_LEVEL = "-O";
319+
TARGETED_DEVICE_FAMILY = 1;
311320
};
312321
name = Release;
313322
};

0 commit comments

Comments
 (0)