Skip to content

Commit

Permalink
fix: notification permission (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
w8385 authored Oct 13, 2024
1 parent b47ed16 commit 525d863
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 21 deletions.
2 changes: 1 addition & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ post_install do |installer|
##'PERMISSION_LOCATION_WHENINUSE=0',

## dart: PermissionGroup.notification
##'PERMISSION_NOTIFICATIONS=1',
'PERMISSION_NOTIFICATIONS=1',

## dart: PermissionGroup.mediaLibrary
##'PERMISSION_MEDIA_LIBRARY=1',
Expand Down
24 changes: 21 additions & 3 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,12 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 74;
DEVELOPMENT_TEAM = 3PFDRPLY6N;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 3PFDRPLY6N;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = MY.SOLVED;
Expand All @@ -390,6 +394,8 @@
MARKETING_VERSION = 2.0.5;
PRODUCT_BUNDLE_IDENTIFIER = com.jeehoukjung.mySolved;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "My.solved distribution";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
Expand Down Expand Up @@ -514,8 +520,12 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 74;
DEVELOPMENT_TEAM = 3PFDRPLY6N;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 3PFDRPLY6N;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = MY.SOLVED;
Expand All @@ -526,6 +536,8 @@
MARKETING_VERSION = 2.0.5;
PRODUCT_BUNDLE_IDENTIFIER = com.jeehoukjung.mySolved;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "My.solved distribution";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
Expand All @@ -544,8 +556,12 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 74;
DEVELOPMENT_TEAM = 3PFDRPLY6N;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 3PFDRPLY6N;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = MY.SOLVED;
Expand All @@ -556,6 +572,8 @@
MARKETING_VERSION = 2.0.5;
PRODUCT_BUNDLE_IDENTIFIER = com.jeehoukjung.mySolved;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "My.solved distribution";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
Expand Down
19 changes: 11 additions & 8 deletions lib/features/contest/bloc/contest_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,18 @@ class ContestBloc extends Bloc<ContestEvent, ContestState> {
ContestNotificationButtonPressed event,
Emitter<ContestState> emit,
) async {
var status = await Permission.notification.status;
if (status.isDenied) {
status = await Permission.notification.request();
} else if (status.isPermanentlyDenied) {
await openAppSettings();
status = await Permission.notification.status;
}
var status = await Permission.notification.request();
if (!status.isGranted) {
Fluttertoast.showToast(
msg: "알림 권한을 허용해주세요.",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: MySolvedColor.main.withOpacity(0.8),
textColor: Colors.white,
fontSize: 16.0);
await Future.delayed(const Duration(seconds: 1));
await openAppSettings();
return;
}

Expand Down Expand Up @@ -144,7 +148,6 @@ class ContestBloc extends Bloc<ContestEvent, ContestState> {
Emitter<ContestState> emit,
) async {
emit(state.copyWith(status: ContestStatus.loading));

final contest = state.filteredUpcomingContests[event.index];
List<bool> isOnCalendar = state.isOnCalendarUpcomingContests;
final isOn = await _sharedPreferencesRepository.getIsOnContestCalendar(
Expand Down
22 changes: 14 additions & 8 deletions lib/features/setting/bloc/setting_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:shared_preferences_repository/shared_preferences_repository.dart';
import 'package:streak_notification_repository/streak_notification_repository.dart';

import '../../../components/styles/color.dart';

part 'setting_event.dart';
part 'setting_state.dart';

Expand Down Expand Up @@ -96,15 +99,18 @@ class SettingBloc extends Bloc<SettingEvent, SettingState> {
SettingStreakNotificationSwitchChanged event,
Emitter<SettingState> emit,
) async {
var status = await Permission.notification.status;
if (status.isDenied) {
status = await Permission.notification.request();
emit(state.copyWith(isOnStreakNotification: status.isGranted));
} else if (status.isPermanentlyDenied) {
await openAppSettings();
emit(state.copyWith(isOnStreakNotification: status.isGranted));
}
var status = await Permission.notification.request();
if (!status.isGranted) {
Fluttertoast.showToast(
msg: "알림 권한을 허용해주세요.",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: MySolvedColor.main.withOpacity(0.8),
textColor: Colors.white,
fontSize: 16.0);
await Future.delayed(const Duration(seconds: 1));
await openAppSettings();
return;
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: For solving problems in the world of programming; base on solved.ac

publish_to: "none" # Remove this line if you wish to publish to pub.dev

version: 2.2.1+82
version: 2.2.1+85

environment:
sdk: ">=2.18.2 <3.0.0"
Expand Down

0 comments on commit 525d863

Please sign in to comment.