Skip to content

Commit

Permalink
Merge pull request #1221 from OneSignal/5.0.0/move_language_to_user
Browse files Browse the repository at this point in the history
[5.0.0] Delete language classes and let properties model itself handle language
  • Loading branch information
nan-li authored Feb 3, 2023
2 parents afedcb4 + f3cfa15 commit 57287d9
Show file tree
Hide file tree
Showing 45 changed files with 1,126 additions and 1,043 deletions.
115 changes: 54 additions & 61 deletions MIGRATION_GUIDE.md

Large diffs are not rendered by default.

17 changes: 6 additions & 11 deletions iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

NSLog(@"Bundle URL: %@", [[NSBundle mainBundle] bundleURL]);
[OneSignal.Debug setLogLevel:ONE_S_LL_VERBOSE];
[OneSignal.Debug setVisualLevel:ONE_S_LL_NONE];
[OneSignal.Debug setAlertLevel:ONE_S_LL_NONE];

[OneSignal initialize:[AppDelegate getOneSignalAppId] withLaunchOptions:launchOptions];

Expand Down Expand Up @@ -84,19 +84,14 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[OneSignal setLaunchURLsInApp:YES];
[OneSignal setProvidesNotificationSettingsView:NO];


[OneSignal.Notifications requestPermission:^(BOOL accepted) {
NSLog(@"OneSignal Demo App requestPermission: %d", accepted);
}];

[OneSignal.InAppMessages setLifecycleHandler:self];
[OneSignal.InAppMessages paused:true];

[OneSignal.Notifications setNotificationWillShowInForegroundHandler:notificationReceiverBlock];
[OneSignal.Notifications setNotificationOpenedHandler:openNotificationHandler];

OSPushSubscriptionState* state = [OneSignal.User.pushSubscription addObserver:self];
NSLog(@"OneSignal Demo App push subscription observer added, current state: %@", state);
[OneSignal.User.pushSubscription addObserver:self];
NSLog(@"OneSignal Demo App push subscription observer added");

[OneSignal.Notifications addPermissionObserver:self];

Expand All @@ -122,12 +117,12 @@ + (void) setOneSignalAppId:(NSString*)onesignalAppId {
// [OneSignal setAppId:onesignalAppId];
}

- (void) onOSPermissionChanged:(OSPermissionStateChanges*)stateChanges {
NSLog(@"onOSPermissionChanged: %@", stateChanges);
- (void)onOSPermissionChanged:(OSPermissionState*)state {
NSLog(@"Dev App onOSPermissionChanged: %@", state);
}

- (void)onOSPushSubscriptionChangedWithStateChanges:(OSPushSubscriptionStateChanges *)stateChanges {
NSLog(@"onOSPushSubscriptionChangedWithStateChanges: %@", stateChanges);
NSLog(@"Dev App onOSPushSubscriptionChangedWithStateChanges: %@", stateChanges);
ViewController* mainController = (ViewController*) self.window.rootViewController;
mainController.subscriptionSegmentedControl.selectedSegmentIndex = (NSInteger) stateChanges.to.optedIn;
}
Expand Down
451 changes: 294 additions & 157 deletions iOS_SDK/OneSignalDevApp/OneSignalDevApp/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class LiveActivityController: NSObject {
@objc
static func createActivity() async -> String? {
if #available(iOS 16.1, *) {
counter += 1;
counter += 1
let attributes = OneSignalWidgetAttributes(title: "#" + String(counter) + " OneSignal Dev App Live Activity")
let contentState = OneSignalWidgetAttributes.ContentState(message: "Update this message through push or with Activity Kit")
do {
Expand All @@ -58,7 +58,7 @@ class LiveActivityController: NSObject {
let myToken = data.map {String(format: "%02x", $0)}.joined()
return myToken
}
} catch (let error) {
} catch let error {
print(error.localizedDescription)
return nil
}
Expand Down
25 changes: 19 additions & 6 deletions iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,29 @@
@property (weak, nonatomic) IBOutlet UITextField *appIdTextField;
@property (weak, nonatomic) IBOutlet UIButton *updateAppIdButton;
@property (weak, nonatomic) IBOutlet UIButton *sendTagButton;
@property (weak, nonatomic) IBOutlet UIButton *getTagsButton;
@property (weak, nonatomic) IBOutlet UIButton *getInfoButton;
@property (weak, nonatomic) IBOutlet UIButton *sendTagsButton;
@property (weak, nonatomic) IBOutlet UIButton *promptPushButton;
@property (weak, nonatomic) IBOutlet UIButton *promptLocationButton;
@property (weak, nonatomic) IBOutlet UISegmentedControl *subscriptionSegmentedControl;
@property (weak, nonatomic) IBOutlet UITextField *emailTextField;
@property (weak, nonatomic) IBOutlet UIButton *setEmailButton;
@property (weak, nonatomic) IBOutlet UIButton *logoutEmailButton;
@property (weak, nonatomic) IBOutlet UIButton *addEmailButton;
@property (weak, nonatomic) IBOutlet UIButton *removeEmailButton;

@property (weak, nonatomic) IBOutlet UITextField *smsTextField;
@property (weak, nonatomic) IBOutlet UIButton *addSmsButton;
@property (weak, nonatomic) IBOutlet UIButton *removeSmsButton;

@property (weak, nonatomic) IBOutlet UITextField *externalUserIdTextField;
@property (weak, nonatomic) IBOutlet UIButton *setExternalUserIdButton;
@property (weak, nonatomic) IBOutlet UIButton *removeExternalUserIdButton;
@property (weak, nonatomic) IBOutlet UIButton *loginExternalUserIdButton;
@property (weak, nonatomic) IBOutlet UIButton *logoutButton;

@property (weak, nonatomic) IBOutlet UITextField *addAliasLabelTextField;
@property (weak, nonatomic) IBOutlet UITextField *addAliasIdTextField;
@property (weak, nonatomic) IBOutlet UIButton *addAliasButton;
@property (weak, nonatomic) IBOutlet UITextField *removeAliasLabelTextField;
@property (weak, nonatomic) IBOutlet UIButton *removeAliasButton;

@property (weak, nonatomic) IBOutlet UISegmentedControl *locationSharedSegementedControl;
@property (weak, nonatomic) IBOutlet UISegmentedControl *inAppMessagingSegmentedControl;
@property (weak, nonatomic) IBOutlet UITextField *addTriggerKey;
Expand All @@ -61,10 +73,11 @@
@property (weak, nonatomic) IBOutlet UITextField *outcomeValueName;
@property (weak, nonatomic) IBOutlet UITextField *outcomeValue;
@property (weak, nonatomic) IBOutlet UITextField *outcomeUniqueName;
@property (weak, nonatomic) IBOutlet UITextView *result;
@property (weak, nonatomic) IBOutlet UITextField *tagKey;
@property (weak, nonatomic) IBOutlet UITextField *tagValue;
@property (weak, nonatomic) IBOutlet UITextField *activityId;

@property (weak, nonatomic) IBOutlet UITextField *languageTextField;

@end

77 changes: 65 additions & 12 deletions iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ - (void)viewDidLoad {

self.consentSegmentedControl.selectedSegmentIndex = (NSInteger) ![OneSignal requiresPrivacyConsent];

// self.subscriptionSegmentedControl.selectedSegmentIndex = (NSInteger) OneSignal.getDeviceState.isSubscribed;
self.subscriptionSegmentedControl.selectedSegmentIndex = (NSInteger) OneSignal.User.pushSubscription.optedIn;

self.locationSharedSegementedControl.selectedSegmentIndex = (NSInteger) [OneSignal.Location isShared];

Expand All @@ -60,7 +60,8 @@ - (void)changeAnimationState:(BOOL)animating {
}

- (IBAction)updateAppId:(id)sender {
[AppDelegate setOneSignalAppId:self.appIdTextField.text];
// [AppDelegate setOneSignalAppId:self.appIdTextField.text];
NSLog(@"Dev App: Not a feature, can't change app id, no op!");
}

- (IBAction)addTriggerAction:(id)sender {
Expand All @@ -84,16 +85,41 @@ - (IBAction)getTriggersAction:(id)sender {
NSLog(@"Getting triggers no longer supported");
}

- (IBAction)setEmailButton:(id)sender {
- (IBAction)addEmailButton:(id)sender {
NSString *email = self.emailTextField.text;
NSLog(@"Adding email with email: %@", email);
NSLog(@"Dev App: add email: %@", email);
[OneSignal.User addEmail:email];
}

- (IBAction)logoutEmailButton:(id)sender {
- (IBAction)removeEmailButton:(id)sender {
NSString *email = self.emailTextField.text;
BOOL canRemove = [OneSignal.User removeEmail:email];
NSLog(@"Removing email with email: %@ and canRemove: %d", email, canRemove);
NSLog(@"Dev App: Removing email: %@", email);
[OneSignal.User removeEmail:email];
}

- (IBAction)addSmsButton:(id)sender {
NSString *sms = self.smsTextField.text;
NSLog(@"Dev App: Add sms: %@", sms);
[OneSignal.User addSms:sms];
}

- (IBAction)removeSmsButton:(id)sender {
NSString *sms = self.smsTextField.text;
NSLog(@"Dev App: Removing sms: %@", sms);
[OneSignal.User removeSms:sms];
}

- (IBAction)addAliasButton:(UIButton *)sender {
NSString* label = self.addAliasLabelTextField.text;
NSString* id = self.addAliasIdTextField.text;
NSLog(@"Dev App: Add alias with label %@ and ID %@", label, id);
[OneSignal.User addAliasWithLabel:label id:id];
}

- (IBAction)removeAliasButton:(UIButton *)sender {
NSString* label = self.removeAliasLabelTextField.text;
NSLog(@"Dev App: Removing alias with label %@", label);
[OneSignal.User removeAlias:label];
}

- (IBAction)sendTagButton:(id)sender {
Expand All @@ -104,8 +130,8 @@ - (IBAction)sendTagButton:(id)sender {
}
}

- (IBAction)getTagsButton:(id)sender {
NSLog(@"getTags no longer supported");
- (IBAction)getInfoButton:(id)sender {
NSLog(@"Dev App: get User and Device information, you need to fill in");
}

- (IBAction)sendTagsButton:(id)sender {
Expand Down Expand Up @@ -147,7 +173,13 @@ - (IBAction)consentSegmentedControlValueChanged:(UISegmentedControl *)sender {

- (IBAction)subscriptionSegmentedControlValueChanged:(UISegmentedControl *)sender {
NSLog(@"View controller subscription status: %i", (int) sender.selectedSegmentIndex);
// [OneSignal disablePush:(bool) !sender.selectedSegmentIndex];
if (sender.selectedSegmentIndex) {
[OneSignal.User.pushSubscription optIn];
} else {
[OneSignal.User.pushSubscription optOut];
}
sender.selectedSegmentIndex = (NSInteger) OneSignal.User.pushSubscription.optedIn;

}

- (IBAction)locationSharedSegmentedControlValueChanged:(UISegmentedControl *)sender {
Expand All @@ -164,13 +196,13 @@ - (void)handleMessageAction:(NSString *)actionId {
NSLog(@"View controller did get action: %@", actionId);
}

- (IBAction)setExternalUserId:(UIButton *)sender {
- (IBAction)loginExternalUserId:(UIButton *)sender {
NSString* externalUserId = self.externalUserIdTextField.text;
NSLog(@"Dev App: Logging in to external user ID %@", externalUserId);
[OneSignal login:externalUserId];
}

- (IBAction)removeExternalUserId:(UIButton *)sender {
- (IBAction)logout:(UIButton *)sender {
NSLog(@"Dev App: Logout called.");
[OneSignal logout];
}
Expand Down Expand Up @@ -223,4 +255,25 @@ - (IBAction)exitLiveActivity:(id)sender {
}
}

- (IBAction)setLanguage:(id)sender {
NSLog(@"Dev App: set language called.");
NSString *language = self.languageTextField.text;
[OneSignal.User setLanguage:language];
}

- (IBAction)clearAllNotifications:(id)sender {
NSLog(@"Dev App: clear All Notifications called.");
[OneSignal.Notifications clearAll];
}

- (IBAction)requireConsent:(id)sender {
NSLog(@"Dev App: setting setRequiresPrivacyConsent to true.");
[OneSignal setRequiresPrivacyConsent:true];
}

- (IBAction)dontRequireConsent:(id)sender {
NSLog(@"Dev App: setting setRequiresPrivacyConsent to false.");
[OneSignal setRequiresPrivacyConsent:false];
}

@end
6 changes: 3 additions & 3 deletions iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
NSLog(@"Bundle URL: %@", [[NSBundle mainBundle] bundleURL]);

[OneSignal.Debug setLogLevel:ONE_S_LL_VERBOSE];
[OneSignal.Debug setVisualLevel:ONE_S_LL_NONE];
[OneSignal.Debug setAlertLevel:ONE_S_LL_NONE];
_notificationDelegate = [OneSignalNotificationCenterDelegate new];

id openNotificationHandler = ^(OSNotificationOpenedResult *result) {
Expand Down Expand Up @@ -112,8 +112,8 @@ + (void) setOneSignalAppId:(NSString*)onesignalAppId {
[OneSignal initialize:onesignalAppId withLaunchOptions:nil];
}

- (void) onOSPermissionChanged:(OSPermissionStateChanges*)stateChanges {
NSLog(@"onOSPermissionChanged: %@", stateChanges);
- (void) onOSPermissionChanged:(OSPermissionState*)state {
NSLog(@"onOSPermissionChanged: %@", state);
}

// TODO: Add push sub observer
Expand Down
Loading

0 comments on commit 57287d9

Please sign in to comment.