Skip to content

Commit 5d49d76

Browse files
Merge pull request #4 from Iterable/feature/ITBL-5296
[ITBL-5296] - Objc Sample App
2 parents 9b175d3 + 45448d5 commit 5d49d76

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1407
-9
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>$(DEVELOPMENT_LANGUAGE)</string>
7+
<key>CFBundleDisplayName</key>
8+
<string>objc-sample-app-notification-extension</string>
9+
<key>CFBundleExecutable</key>
10+
<string>$(EXECUTABLE_NAME)</string>
11+
<key>CFBundleIdentifier</key>
12+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>6.0</string>
15+
<key>CFBundleName</key>
16+
<string>$(PRODUCT_NAME)</string>
17+
<key>CFBundlePackageType</key>
18+
<string>XPC!</string>
19+
<key>CFBundleShortVersionString</key>
20+
<string>1.0</string>
21+
<key>CFBundleVersion</key>
22+
<string>1</string>
23+
<key>NSExtension</key>
24+
<dict>
25+
<key>NSExtensionPointIdentifier</key>
26+
<string>com.apple.usernotifications.service</string>
27+
<key>NSExtensionPrincipalClass</key>
28+
<string>NotificationService</string>
29+
</dict>
30+
</dict>
31+
</plist>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// NotificationService.h
3+
// objc-sample-app-notification-extension
4+
//
5+
// Created by Tapash Majumder on 6/21/18.
6+
// Copyright © 2018 Iterable. All rights reserved.
7+
//
8+
9+
#import <UserNotifications/UserNotifications.h>
10+
11+
12+
@interface NotificationService : UNNotificationServiceExtension
13+
14+
@end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// NotificationService.m
3+
// objc-sample-app-notification-extension
4+
//
5+
// Created by Tapash Majumder on 6/21/18.
6+
// Copyright © 2018 Iterable. All rights reserved.
7+
//
8+
9+
#import "NotificationService.h"
10+
11+
@import IterableAppExtensions;
12+
13+
@interface NotificationService ()
14+
15+
@property (nonatomic, strong) ITBNotificationServiceExtension *baseExtension;
16+
17+
@end
18+
19+
@implementation NotificationService
20+
21+
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
22+
23+
self.baseExtension = [[ITBNotificationServiceExtension alloc] init];
24+
[self.baseExtension didReceiveNotificationRequest:request withContentHandler:contentHandler];
25+
}
26+
27+
- (void)serviceExtensionTimeWillExpire {
28+
[self.baseExtension serviceExtensionTimeWillExpire];
29+
}
30+
31+
@end

objc-sample-app/AppDelegate.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// AppDelegate.h
3+
// objc-sample-app
4+
//
5+
// Created by Tapash Majumder on 6/21/18.
6+
// Copyright © 2018 Iterable. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
#import <UserNotifications/UserNotifications.h>
11+
12+
@interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>
13+
14+
@property (strong, nonatomic) UIWindow *window;
15+
16+
17+
@end
18+

objc-sample-app/AppDelegate.m

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
//
2+
// AppDelegate.m
3+
// objc-sample-app
4+
//
5+
// Created by Tapash Majumder on 6/21/18.
6+
// Copyright © 2018 Iterable. All rights reserved.
7+
//
8+
9+
10+
#import "AppDelegate.h"
11+
#import "DeeplinkHandler.h"
12+
13+
@import IterableSDK;
14+
15+
@interface AppDelegate ()
16+
17+
@end
18+
19+
@implementation AppDelegate
20+
21+
22+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
23+
//ITBL: Setup Notifications
24+
[self setupNotifications];
25+
26+
//ITBL: Initialize API
27+
IterableConfig *config = [[IterableConfig alloc] init];
28+
[IterableAPI initializeWithApiKey:@"a415841b631a4c97924bc09660c658fc"
29+
launchOptions:launchOptions
30+
config:config
31+
32+
userId:nil];
33+
34+
return YES;
35+
}
36+
37+
38+
- (void)applicationWillResignActive:(UIApplication *)application {
39+
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
40+
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
41+
}
42+
43+
44+
- (void)applicationDidEnterBackground:(UIApplication *)application {
45+
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
46+
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
47+
}
48+
49+
50+
- (void)applicationWillEnterForeground:(UIApplication *)application {
51+
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
52+
}
53+
54+
55+
- (void)applicationDidBecomeActive:(UIApplication *)application {
56+
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
57+
}
58+
59+
60+
- (void)applicationWillTerminate:(UIApplication *)application {
61+
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
62+
}
63+
64+
#pragma mark - Url handling
65+
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
66+
67+
//ITBL:
68+
NSURL *url = userActivity.webpageURL;
69+
if (url == nil) {
70+
return NO;
71+
}
72+
73+
[IterableAPI resolveWithApplinkURL:url callbackBlock:^(NSURL *resolvedUrl) {
74+
dispatch_async(dispatch_get_main_queue(), ^{
75+
[DeeplinkHandler handleURL:resolvedUrl];
76+
});
77+
}];
78+
79+
return [DeeplinkHandler canHandleURL:url];
80+
}
81+
82+
#pragma mark - notification registration
83+
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
84+
[IterableAPI.instance registerToken:deviceToken appName:@"objc-sample-app" pushServicePlatform:APNS_SANDBOX];
85+
}
86+
87+
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
88+
//TODO: handle
89+
}
90+
91+
#pragma mark - UNUserNotificationCenterDelegate
92+
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
93+
completionHandler (UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound);
94+
}
95+
96+
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
97+
[IterableAppIntegration userNotificationCenter:center didReceive:response withCompletionHandler:completionHandler];
98+
}
99+
100+
#pragma mark - private
101+
//ITBL:
102+
// Ask for permission for notifications etc.
103+
// setup self as delegate to listen to push notifications.
104+
- (void) setupNotifications {
105+
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
106+
center.delegate = self;
107+
[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
108+
if (settings.authorizationStatus != UNAuthorizationStatusAuthorized) {
109+
// not authorized, ask for permission
110+
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {
111+
if (granted) {
112+
dispatch_async(dispatch_get_main_queue(), ^{
113+
[UIApplication.sharedApplication registerForRemoteNotifications];
114+
});
115+
} // TODO: handle errors
116+
}];
117+
} else {
118+
// already authorized
119+
dispatch_async(dispatch_get_main_queue(), ^{
120+
[UIApplication.sharedApplication registerForRemoteNotifications];
121+
});
122+
}
123+
}];
124+
}
125+
126+
@end
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
"images" : [
3+
{
4+
"size" : "20x20",
5+
"idiom" : "iphone",
6+
"filename" : "[email protected]",
7+
"scale" : "2x"
8+
},
9+
{
10+
"size" : "20x20",
11+
"idiom" : "iphone",
12+
"filename" : "[email protected]",
13+
"scale" : "3x"
14+
},
15+
{
16+
"size" : "29x29",
17+
"idiom" : "iphone",
18+
"filename" : "[email protected]",
19+
"scale" : "2x"
20+
},
21+
{
22+
"size" : "29x29",
23+
"idiom" : "iphone",
24+
"filename" : "[email protected]",
25+
"scale" : "3x"
26+
},
27+
{
28+
"size" : "40x40",
29+
"idiom" : "iphone",
30+
"filename" : "[email protected]",
31+
"scale" : "2x"
32+
},
33+
{
34+
"size" : "40x40",
35+
"idiom" : "iphone",
36+
"filename" : "[email protected]",
37+
"scale" : "3x"
38+
},
39+
{
40+
"size" : "60x60",
41+
"idiom" : "iphone",
42+
"filename" : "[email protected]",
43+
"scale" : "2x"
44+
},
45+
{
46+
"size" : "60x60",
47+
"idiom" : "iphone",
48+
"filename" : "[email protected]",
49+
"scale" : "3x"
50+
},
51+
{
52+
"size" : "20x20",
53+
"idiom" : "ipad",
54+
"filename" : "Icon-App20x20.png",
55+
"scale" : "1x"
56+
},
57+
{
58+
"size" : "20x20",
59+
"idiom" : "ipad",
60+
"filename" : "[email protected]",
61+
"scale" : "2x"
62+
},
63+
{
64+
"size" : "29x29",
65+
"idiom" : "ipad",
66+
"filename" : "Icon-App29x29.png",
67+
"scale" : "1x"
68+
},
69+
{
70+
"size" : "29x29",
71+
"idiom" : "ipad",
72+
"filename" : "[email protected]",
73+
"scale" : "2x"
74+
},
75+
{
76+
"size" : "40x40",
77+
"idiom" : "ipad",
78+
"filename" : "Icon-App40x40.png",
79+
"scale" : "1x"
80+
},
81+
{
82+
"size" : "40x40",
83+
"idiom" : "ipad",
84+
"filename" : "[email protected]",
85+
"scale" : "2x"
86+
},
87+
{
88+
"size" : "76x76",
89+
"idiom" : "ipad",
90+
"filename" : "Icon-App76x76.png",
91+
"scale" : "1x"
92+
},
93+
{
94+
"size" : "76x76",
95+
"idiom" : "ipad",
96+
"filename" : "[email protected]",
97+
"scale" : "2x"
98+
},
99+
{
100+
"size" : "83.5x83.5",
101+
"idiom" : "ipad",
102+
"filename" : "[email protected]",
103+
"scale" : "2x"
104+
},
105+
{
106+
"size" : "1024x1024",
107+
"idiom" : "ios-marketing",
108+
"filename" : "[email protected]",
109+
"scale" : "1x"
110+
}
111+
],
112+
"info" : {
113+
"version" : 1,
114+
"author" : "xcode"
115+
}
116+
}
6.26 KB
Loading
5.08 KB
Loading
7.89 KB
Loading
3.26 KB
Loading

0 commit comments

Comments
 (0)