Skip to content

Commit ad0fc5d

Browse files
committed
testing ephemeral
1 parent b8383ab commit ad0fc5d

File tree

5 files changed

+68
-43
lines changed

5 files changed

+68
-43
lines changed

iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
5656

5757
id openNotificationHandler = ^(OSNotificationOpenedResult *result) {
5858
NSLog(@"OSNotificationOpenedResult: %@", result.action);
59-
59+
6060
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Notifiation Opened In App Delegate" message:@"Notification Opened In App Delegate" delegate:self cancelButtonTitle:@"Delete" otherButtonTitles:@"Cancel", nil];
6161
[alert show];
6262
};
@@ -86,7 +86,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
8686
[OneSignal addEmailSubscriptionObserver:self];
8787

8888
[OneSignal pauseInAppMessages:true];
89-
89+
9090
[OneSignal setNotificationWillShowInForegroundHandler:notificationReceiverBlock];
9191
[OneSignal setNotificationOpenedHandler:openNotificationHandler];
9292

iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/AppDelegate.m

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,38 @@
3131
#import "AppDelegate.h"
3232
#import "ViewController.h"
3333

34+
@interface OneSignalNotificationCenterDelegate: NSObject<UNUserNotificationCenterDelegate>
35+
@end
36+
@implementation OneSignalNotificationCenterDelegate
37+
38+
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
39+
NSLog(@"Appdelegatewillpresentdelegate");
40+
}
41+
42+
@end
43+
3444
@implementation AppDelegate
3545

46+
OneSignalNotificationCenterDelegate *_notificationDelegate;
47+
3648
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
3749

3850
// [FIRApp configure];
3951

4052
NSLog(@"Bundle URL: %@", [[NSBundle mainBundle] bundleURL]);
4153

4254
[OneSignal setLogLevel:ONE_S_LL_VERBOSE visualLevel:ONE_S_LL_NONE];
43-
44-
OneSignal.inFocusDisplayType = OSNotificationDisplayTypeInAppAlert;
55+
_notificationDelegate = [OneSignalNotificationCenterDelegate new];
4556

4657
id openNotificationHandler = ^(OSNotificationOpenedResult *result) {
47-
NSLog(@"OSNotificationOpenedResult: %@", result);
58+
NSLog(@"OSNotificationOpenedResult: %@", result.action);
59+
60+
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Notifiation Opened In App Delegate" message:@"Notification Opened In App Delegate" delegate:self cancelButtonTitle:@"Delete" otherButtonTitles:@"Cancel", nil];
61+
[alert show];
4862
};
49-
50-
id notificationReceiverBlock = ^(OSNotification *notification) {
51-
NSLog(@"Received Notification - %@", notification.payload.notificationID);
63+
id notificationReceiverBlock = ^(OSNotification *notif, OSNotificationDisplayResponse completion) {
64+
NSLog(@"Will Receive Notification - %@", notif.notificationId);
65+
completion(notif);
5266
};
5367

5468
// Example block for IAM action click handler
@@ -59,23 +73,22 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
5973

6074
// Example setter for IAM action click handler using OneSignal public method
6175
[OneSignal setInAppMessageClickHandler:inAppMessagingActionClickBlock];
62-
63-
[OneSignal initWithLaunchOptions:launchOptions
64-
appId:[AppDelegate getOneSignalAppId]
65-
handleNotificationReceived:notificationReceiverBlock
66-
handleNotificationAction:openNotificationHandler
67-
settings:@{kOSSettingsKeyAutoPrompt: @false,
68-
kOSSettingsKeyInAppLaunchURL: @true}];
6976

70-
// [OneSignal setLocationShared:false];
71-
72-
[OneSignal sendTag:@"someKey1122" value:@"03222017"];
77+
// OneSignal Init with app settings, app id, and lauch options
78+
[OneSignal setAppSettings:@{
79+
kOSSettingsKeyInAppLaunchURL: @true
80+
}];
81+
[OneSignal setAppId:[AppDelegate getOneSignalAppId]];
82+
[OneSignal initWithLaunchOptions:launchOptions];
7383

7484
[OneSignal addPermissionObserver:self];
7585
[OneSignal addSubscriptionObserver:self];
7686
[OneSignal addEmailSubscriptionObserver:self];
7787

78-
[OneSignal pauseInAppMessages:false];
88+
[OneSignal pauseInAppMessages:true];
89+
90+
[OneSignal setNotificationWillShowInForegroundHandler:notificationReceiverBlock];
91+
[OneSignal setNotificationOpenedHandler:openNotificationHandler];
7992

8093
NSLog(@"UNUserNotificationCenter.delegate: %@", UNUserNotificationCenter.currentNotificationCenter.delegate);
8194

@@ -85,9 +98,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
8598
#define ONESIGNAL_APP_ID_KEY_FOR_TESTING @"8e04addd-be31-43dc-8c7a-0618eb781972"
8699

87100
+ (NSString*)getOneSignalAppId {
101+
NSString* newAppId = @"8e04addd-be31-43dc-8c7a-0618eb781972";
88102
NSString* onesignalAppId = [[NSUserDefaults standardUserDefaults] objectForKey:ONESIGNAL_APP_ID_KEY_FOR_TESTING];
89-
if (!onesignalAppId)
90-
onesignalAppId = @"8e04addd-be31-43dc-8c7a-0618eb781972";
103+
104+
if (![newAppId isEqualToString:onesignalAppId]) {
105+
[self setOneSignalAppId:newAppId];
106+
onesignalAppId = newAppId;
107+
}
91108

92109
return onesignalAppId;
93110
}

iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/ViewController.m

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ - (void)viewDidLoad {
4141

4242
self.consentSegmentedControl.selectedSegmentIndex = (NSInteger) ![OneSignal requiresUserPrivacyConsent];
4343

44-
self.subscriptionSegmentedControl.selectedSegmentIndex = (NSInteger) OneSignal.getUserDevice.isSubscribed;
44+
self.subscriptionSegmentedControl.selectedSegmentIndex = (NSInteger) OneSignal.getDeviceState.isSubscribed;
4545

4646
self.locationSharedSegementedControl.selectedSegmentIndex = (NSInteger) OneSignal.isLocationShared;
4747

@@ -102,10 +102,6 @@ - (IBAction)logoutEmailButton:(id)sender {
102102
}
103103

104104
- (IBAction)getTagsButton:(id)sender {
105-
[OneSignal IdsAvailable:^(NSString *userId, NSString *pushToken) {
106-
NSLog(@"IdsAvailable userId: %@, and pushToken: %@", userId, pushToken);
107-
}];
108-
109105
[OneSignal getTags:^(NSDictionary *result) {
110106
NSLog(@"Tags: %@", result.description);
111107
}];
@@ -126,7 +122,6 @@ - (IBAction)sendTagButton:(id)sender {
126122

127123
- (IBAction)promptPushAction:(UIButton *)sender {
128124
// [self promptForNotificationsWithNativeiOS10Code];
129-
// [OneSignal registerForPushNotifications];
130125
[OneSignal promptForPushNotificationsWithUserResponse:^(BOOL accepted) {
131126
NSLog(@"OneSignal Demo App promptForPushNotificationsWithUserResponse: %d", accepted);
132127
}];
@@ -158,7 +153,7 @@ - (IBAction)consentSegmentedControlValueChanged:(UISegmentedControl *)sender {
158153

159154
- (IBAction)subscriptionSegmentedControlValueChanged:(UISegmentedControl *)sender {
160155
NSLog(@"View controller subscription status: %i", (int) sender.selectedSegmentIndex);
161-
[OneSignal setSubscription:(bool) sender.selectedSegmentIndex];
156+
[OneSignal disablePush:(bool) !sender.selectedSegmentIndex];
162157
}
163158

164159
- (IBAction)locationSharedSegmentedControlValueChanged:(UISegmentedControl *)sender {

iOS_SDK/OneSignalDevApp/OneSignalExample.xcodeproj/project.pbxproj

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,11 @@
601601
);
602602
INFOPLIST_FILE = OneSignalDevApp/Info.plist;
603603
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
604-
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
604+
LD_RUNPATH_SEARCH_PATHS = (
605+
"$(inherited)",
606+
"@executable_path/Frameworks",
607+
);
608+
MARKETING_VERSION = 1.3;
605609
OTHER_LDFLAGS = "-ObjC";
606610
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example;
607611
PRODUCT_NAME = OneSignalExample;
@@ -623,7 +627,11 @@
623627
);
624628
INFOPLIST_FILE = OneSignalDevApp/Info.plist;
625629
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
626-
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
630+
LD_RUNPATH_SEARCH_PATHS = (
631+
"$(inherited)",
632+
"@executable_path/Frameworks",
633+
);
634+
MARKETING_VERSION = 1.3;
627635
OTHER_LDFLAGS = "-ObjC";
628636
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example;
629637
PRODUCT_NAME = OneSignalExample;

iOS_SDK/OneSignalSDK/Source/OneSignal.m

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ + (BOOL)handleAppIdChange:(NSString*)appId {
663663
initDone = false;
664664
_downloadedParameters = false;
665665
_didCallDownloadParameters = false;
666-
666+
667667
let sharedUserDefaults = OneSignalUserDefaults.initShared;
668668

669669
[standardUserDefaults saveStringForKey:OSUD_APP_ID withValue:appId];
@@ -707,9 +707,14 @@ + (void)initSettings:(NSDictionary*)settings {
707707
providesAppNotificationSettings = [settings[kOSSettingsKeyProvidesAppNotificationSettings] boolValue];
708708

709709
// Register with Apple's APNS server if we registed once before or if auto-prompt hasn't been disabled.
710-
if (usesAutoPrompt || registeredWithApple)
710+
if (usesAutoPrompt || registeredWithApple) {
711+
onesignal_Log(ONE_S_LL_VERBOSE, @"uses auto prompt or registered with apple");
712+
if (usesAutoPrompt)
713+
onesignal_Log(ONE_S_LL_VERBOSE, @"uses auto prompt");
714+
if (registeredWithApple)
715+
onesignal_Log(ONE_S_LL_VERBOSE, @"registered with apple");
711716
[self registerForPushNotifications];
712-
else {
717+
} else {
713718
[self checkProvisionalAuthorizationStatus];
714719
[self registerForAPNsToken];
715720
}
@@ -769,12 +774,12 @@ + (void)setRequiresUserPrivacyConsent:(BOOL)required {
769774
// Already set by remote params
770775
if ([remoteParamController hasPrivacyConsentKey])
771776
return;
772-
777+
773778
if ([self requiresUserPrivacyConsent] && !required) {
774779
[OneSignal onesignal_Log:ONE_S_LL_ERROR message:@"Cannot change requiresUserPrivacyConsent() from TRUE to FALSE"];
775780
return;
776781
}
777-
782+
778783
[remoteParamController savePrivacyConsentRequired:required];
779784
}
780785

@@ -837,8 +842,8 @@ + (void)downloadIOSParamsWithAppId:(NSString *)appId {
837842

838843
if (result[IOS_RECEIVE_RECEIPTS_ENABLE] != (id)[NSNull null])
839844
[OneSignalUserDefaults.initShared saveBoolForKey:OSUD_RECEIVE_RECEIPTS_ENABLED withValue:[result[IOS_RECEIVE_RECEIPTS_ENABLE] boolValue]];
840-
841-
845+
846+
842847
//TODO: move all remote param logic to new OSRemoteParamController
843848
[[self getRemoteParamController] saveRemoteParams:result];
844849

@@ -1402,13 +1407,13 @@ + (void)setLocationShared:(BOOL)enable {
14021407
// Already set by remote params
14031408
if ([remoteController hasLocationKey])
14041409
return;
1405-
1410+
14061411
[self startLocationSharedWithFlag:enable];
14071412
}
14081413

14091414
+ (void)startLocationSharedWithFlag:(BOOL)enable {
14101415
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"startLocationSharedWithFlag called with status: %d", (int) enable]];
1411-
1416+
14121417
let remoteController = [self getRemoteParamController];
14131418
[remoteController saveLocationShared:enable];
14141419

@@ -1768,7 +1773,7 @@ + (void)registerUserInternal {
17681773
[OneSignal setEmail:emailToSet];
17691774
emailToSet = nil;
17701775
}
1771-
1776+
17721777
[self sendNotificationTypesUpdate];
17731778

17741779
if (pendingGetTagsSuccessBlock) {
@@ -1862,7 +1867,7 @@ + (BOOL)sendNotificationTypesUpdate {
18621867
[self.currentSubscriptionState setAccepted:[self getNotificationTypes] > 0];
18631868

18641869
} onFailure:nil];
1865-
1870+
18661871
return true;
18671872
}
18681873

@@ -1933,7 +1938,7 @@ + (void)notificationReceived:(NSDictionary*)messageDict foreground:(BOOL)foregro
19331938
if (isPreview && [OneSignalHelper isIOSVersionLessThan:@"10.0"]) {
19341939
return;
19351940
}
1936-
1941+
19371942
if (opened) {
19381943
// Prevent duplicate calls
19391944
let newId = [self checkForProcessedDups:customDict lastMessageId:_lastnonActiveMessageId];
@@ -1972,7 +1977,7 @@ + (void)handleWillPresentNotificationInForegroundWithPayload:(NSDictionary *)pay
19721977
return;
19731978
}
19741979
//Only call the willShowInForegroundHandler for notifications not preview IAMs
1975-
1980+
19761981
OSNotification *osNotification = [OSNotification parseWithApns:payload];
19771982
if ([osNotification additionalData][ONESIGNAL_IAM_PREVIEW]) {
19781983
completion(nil);

0 commit comments

Comments
 (0)