├── .editorconfig ├── .gitattributes ├── .github └── ISSUE_TEMPLATE │ └── bug_report.md ├── .gitignore ├── LICENSE ├── README.md ├── XamarinForms.LocationService.Android ├── Assets │ └── AboutAssets.txt ├── BootBroadcastReceiver.cs ├── CurrentActivityUtil.cs ├── Helpers │ ├── INotification.cs │ └── NotificationHelper.cs ├── MainActivity.cs ├── MainApplication.cs ├── PermissionConsent.cs ├── Properties │ ├── AndroidManifest.xml │ └── AssemblyInfo.cs ├── Resources │ ├── AboutResources.txt │ ├── Resource.designer.cs │ ├── drawable │ │ └── location.png │ ├── layout │ │ ├── Tabbar.xml │ │ └── Toolbar.xml │ ├── mipmap-anydpi-v26 │ │ ├── icon.xml │ │ └── icon_round.xml │ ├── mipmap-hdpi │ │ ├── icon.png │ │ └── launcher_foreground.png │ ├── mipmap-mdpi │ │ ├── icon.png │ │ └── launcher_foreground.png │ ├── mipmap-xhdpi │ │ ├── icon.png │ │ └── launcher_foreground.png │ ├── mipmap-xxhdpi │ │ ├── icon.png │ │ └── launcher_foreground.png │ ├── mipmap-xxxhdpi │ │ ├── icon.png │ │ └── launcher_foreground.png │ └── values │ │ ├── colors.xml │ │ └── styles.xml ├── Services │ └── AndroidLocationService.cs └── XamarinForms.LocationService.Android.csproj ├── XamarinForms.LocationService.iOS ├── AppDelegate.cs ├── Assets.xcassets │ └── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── Icon1024.png │ │ ├── Icon120.png │ │ ├── Icon152.png │ │ ├── Icon167.png │ │ ├── Icon180.png │ │ ├── Icon20.png │ │ ├── Icon29.png │ │ ├── Icon40.png │ │ ├── Icon58.png │ │ ├── Icon60.png │ │ ├── Icon76.png │ │ ├── Icon80.png │ │ └── Icon87.png ├── Entitlements.plist ├── Info.plist ├── LocationManager.cs ├── Main.cs ├── PermissionConsent.cs ├── Properties │ └── AssemblyInfo.cs ├── Resources │ ├── Default-568h@2x.png │ ├── Default-Portrait.png │ ├── Default-Portrait@2x.png │ ├── Default.png │ ├── Default@2x.png │ └── LaunchScreen.storyboard ├── Services │ └── iOsLocationService.cs └── XamarinForms.LocationService.iOS.csproj ├── XamarinForms.LocationService.sln ├── XamarinForms.LocationService ├── App.xaml ├── App.xaml.cs ├── AppService.cs ├── AssemblyInfo.cs ├── IPermissionConsent.cs ├── MainPage.xaml ├── MainPage.xaml.cs ├── MauiProgram.cs ├── Messages │ ├── LocationErrorMessage.cs │ ├── LocationUpdate.cs │ └── ServiceMessage.cs ├── Models │ └── LocationModel.cs ├── Services │ └── Location.cs ├── Utils │ ├── ActionsEnum.cs │ ├── Constants.cs │ └── PermissionHelper.cs ├── ViewModels │ ├── BaseViewModel.cs │ └── MainPageViewModel.cs └── XamarinForms.LocationService.csproj ├── iOsLocationService.cs └── screenshot.jpeg /.editorconfig: -------------------------------------------------------------------------------- 1 | # Remove the line below if you want to inherit .editorconfig settings from higher directories 2 | root = true 3 | 4 | # C# files 5 | [*.cs] 6 | 7 | #### Core EditorConfig Options #### 8 | 9 | # Indentation and spacing 10 | indent_size = 4 11 | indent_style = space 12 | tab_width = 4 13 | 14 | # New line preferences 15 | end_of_line = crlf 16 | insert_final_newline = false 17 | 18 | #### .NET Coding Conventions #### 19 | 20 | # Organize usings 21 | dotnet_separate_import_directive_groups = false 22 | dotnet_sort_system_directives_first = false 23 | file_header_template = Copyright (c) 2024 Sergio Hernandez. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the "License").\n You may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an "AS IS" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n 24 | 25 | # this. and Me. preferences 26 | dotnet_style_qualification_for_event = false 27 | dotnet_style_qualification_for_field = false 28 | dotnet_style_qualification_for_method = false 29 | dotnet_style_qualification_for_property = false 30 | 31 | # Language keywords vs BCL types preferences 32 | dotnet_style_predefined_type_for_locals_parameters_members = true 33 | dotnet_style_predefined_type_for_member_access = true 34 | 35 | # Parentheses preferences 36 | dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity 37 | dotnet_style_parentheses_in_other_binary_operators = always_for_clarity 38 | dotnet_style_parentheses_in_other_operators = never_if_unnecessary 39 | dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity 40 | 41 | # Modifier preferences 42 | dotnet_style_require_accessibility_modifiers = for_non_interface_members 43 | 44 | # Expression-level preferences 45 | dotnet_style_coalesce_expression = true 46 | dotnet_style_collection_initializer = true 47 | dotnet_style_explicit_tuple_names = true 48 | dotnet_style_namespace_match_folder = true 49 | dotnet_style_null_propagation = true 50 | dotnet_style_object_initializer = true 51 | dotnet_style_operator_placement_when_wrapping = beginning_of_line 52 | dotnet_style_prefer_auto_properties = true 53 | dotnet_style_prefer_collection_expression = when_types_loosely_match 54 | dotnet_style_prefer_compound_assignment = true 55 | dotnet_style_prefer_conditional_expression_over_assignment = true 56 | dotnet_style_prefer_conditional_expression_over_return = true 57 | dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed 58 | dotnet_style_prefer_inferred_anonymous_type_member_names = true 59 | dotnet_style_prefer_inferred_tuple_names = true 60 | dotnet_style_prefer_is_null_check_over_reference_equality_method = true 61 | dotnet_style_prefer_simplified_boolean_expressions = true 62 | dotnet_style_prefer_simplified_interpolation = true 63 | 64 | # Field preferences 65 | dotnet_style_readonly_field = true 66 | 67 | # Parameter preferences 68 | dotnet_code_quality_unused_parameters = all 69 | 70 | # Suppression preferences 71 | dotnet_remove_unnecessary_suppression_exclusions = none 72 | 73 | # New line preferences 74 | dotnet_style_allow_multiple_blank_lines_experimental = true 75 | dotnet_style_allow_statement_immediately_after_block_experimental = true 76 | 77 | #### C# Coding Conventions #### 78 | 79 | # var preferences 80 | csharp_style_var_elsewhere = false 81 | csharp_style_var_for_built_in_types = false 82 | csharp_style_var_when_type_is_apparent = false 83 | 84 | # Expression-bodied members 85 | csharp_style_expression_bodied_accessors = true 86 | csharp_style_expression_bodied_constructors = false 87 | csharp_style_expression_bodied_indexers = true 88 | csharp_style_expression_bodied_lambdas = true 89 | csharp_style_expression_bodied_local_functions = false 90 | csharp_style_expression_bodied_methods = false 91 | csharp_style_expression_bodied_operators = false 92 | csharp_style_expression_bodied_properties = true 93 | 94 | # Pattern matching preferences 95 | csharp_style_pattern_matching_over_as_with_null_check = true 96 | csharp_style_pattern_matching_over_is_with_cast_check = true 97 | csharp_style_prefer_extended_property_pattern = true 98 | csharp_style_prefer_not_pattern = true 99 | csharp_style_prefer_pattern_matching = true 100 | csharp_style_prefer_switch_expression = true 101 | 102 | # Null-checking preferences 103 | csharp_style_conditional_delegate_call = true 104 | 105 | # Modifier preferences 106 | csharp_prefer_static_local_function = true 107 | csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async 108 | csharp_style_prefer_readonly_struct = true 109 | csharp_style_prefer_readonly_struct_member = true 110 | 111 | # Code-block preferences 112 | csharp_prefer_braces = true 113 | csharp_prefer_simple_using_statement = true 114 | csharp_style_namespace_declarations = block_scoped 115 | csharp_style_prefer_method_group_conversion = true 116 | csharp_style_prefer_primary_constructors = true 117 | csharp_style_prefer_top_level_statements = true 118 | 119 | # Expression-level preferences 120 | csharp_prefer_simple_default_expression = true 121 | csharp_style_deconstructed_variable_declaration = true 122 | csharp_style_implicit_object_creation_when_type_is_apparent = true 123 | csharp_style_inlined_variable_declaration = true 124 | csharp_style_prefer_index_operator = true 125 | csharp_style_prefer_local_over_anonymous_function = true 126 | csharp_style_prefer_null_check_over_type_check = true 127 | csharp_style_prefer_range_operator = true 128 | csharp_style_prefer_tuple_swap = true 129 | csharp_style_prefer_utf8_string_literals = true 130 | csharp_style_throw_expression = true 131 | csharp_style_unused_value_assignment_preference = discard_variable 132 | csharp_style_unused_value_expression_statement_preference = discard_variable 133 | 134 | # 'using' directive preferences 135 | csharp_using_directive_placement = outside_namespace 136 | 137 | # New line preferences 138 | csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true 139 | csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true 140 | csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true 141 | csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true 142 | csharp_style_allow_embedded_statements_on_same_line_experimental = true 143 | 144 | #### C# Formatting Rules #### 145 | 146 | # New line preferences 147 | csharp_new_line_before_catch = true 148 | csharp_new_line_before_else = true 149 | csharp_new_line_before_finally = true 150 | csharp_new_line_before_members_in_anonymous_types = true 151 | csharp_new_line_before_members_in_object_initializers = true 152 | csharp_new_line_before_open_brace = all 153 | csharp_new_line_between_query_expression_clauses = true 154 | 155 | # Indentation preferences 156 | csharp_indent_block_contents = true 157 | csharp_indent_braces = false 158 | csharp_indent_case_contents = true 159 | csharp_indent_case_contents_when_block = true 160 | csharp_indent_labels = one_less_than_current 161 | csharp_indent_switch_labels = true 162 | 163 | # Space preferences 164 | csharp_space_after_cast = false 165 | csharp_space_after_colon_in_inheritance_clause = true 166 | csharp_space_after_comma = true 167 | csharp_space_after_dot = false 168 | csharp_space_after_keywords_in_control_flow_statements = true 169 | csharp_space_after_semicolon_in_for_statement = true 170 | csharp_space_around_binary_operators = before_and_after 171 | csharp_space_around_declaration_statements = false 172 | csharp_space_before_colon_in_inheritance_clause = true 173 | csharp_space_before_comma = false 174 | csharp_space_before_dot = false 175 | csharp_space_before_open_square_brackets = false 176 | csharp_space_before_semicolon_in_for_statement = false 177 | csharp_space_between_empty_square_brackets = false 178 | csharp_space_between_method_call_empty_parameter_list_parentheses = false 179 | csharp_space_between_method_call_name_and_opening_parenthesis = false 180 | csharp_space_between_method_call_parameter_list_parentheses = false 181 | csharp_space_between_method_declaration_empty_parameter_list_parentheses = false 182 | csharp_space_between_method_declaration_name_and_open_parenthesis = false 183 | csharp_space_between_method_declaration_parameter_list_parentheses = false 184 | csharp_space_between_parentheses = false 185 | csharp_space_between_square_brackets = false 186 | 187 | # Wrapping preferences 188 | csharp_preserve_single_line_blocks = true 189 | csharp_preserve_single_line_statements = true 190 | 191 | #### Naming styles #### 192 | 193 | # Naming rules 194 | 195 | dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion 196 | dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface 197 | dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i 198 | 199 | dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion 200 | dotnet_naming_rule.types_should_be_pascal_case.symbols = types 201 | dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case 202 | 203 | dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion 204 | dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members 205 | dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case 206 | 207 | # Symbol specifications 208 | 209 | dotnet_naming_symbols.interface.applicable_kinds = interface 210 | dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected 211 | dotnet_naming_symbols.interface.required_modifiers = 212 | 213 | dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum 214 | dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected 215 | dotnet_naming_symbols.types.required_modifiers = 216 | 217 | dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method 218 | dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected 219 | dotnet_naming_symbols.non_field_members.required_modifiers = 220 | 221 | # Naming styles 222 | 223 | dotnet_naming_style.pascal_case.required_prefix = 224 | dotnet_naming_style.pascal_case.required_suffix = 225 | dotnet_naming_style.pascal_case.word_separator = 226 | dotnet_naming_style.pascal_case.capitalization = pascal_case 227 | 228 | dotnet_naming_style.begins_with_i.required_prefix = I 229 | dotnet_naming_style.begins_with_i.required_suffix = 230 | dotnet_naming_style.begins_with_i.word_separator = 231 | dotnet_naming_style.begins_with_i.capitalization = pascal_case 232 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Background Location Service 2 | 3 | XamarinForms.LocationService is an application that refreshes GPS location every n seconds. Over the years, I've been developing mobile apps requiring location features. Hopefully, this project will save you time regarding service and location management in your ~~Xamarin~~ Net application for Android and iOS. 4 | 5 | - Location Updates 6 | - Location Permissions Management 7 | - Background Processing Management 8 | 9 | For documentation related to the Background Services in Android/iOS, you can refer to this [tutorial](https://www.youtube.com/watch?v=Z1YzyreS4-o). It served as the basis for how I started to build a solution for periodic location updates. 10 | 11 | For migrating from Xamarin.Forms to MAUI, you can follow this [link](https://learn.microsoft.com/en-us/dotnet/maui/migration/?view=net-maui-8.0) 12 | 13 | ## The application has been migrated to MAUI. 14 | 15 | # Components used 16 | 17 | - MAUI 18 | - CLLocationManager 19 | 20 | ![Image](https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/master/screenshot.jpeg) 21 | 22 | ## Android: 23 | "Be aware that you might need to adjust battery saver settings on some devices manually to allow the application to continue working in the background." 24 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Assets/AboutAssets.txt: -------------------------------------------------------------------------------- 1 | Any raw assets you want to be deployed with your application can be placed in 2 | this directory (and child directories) and given a Build Action of "AndroidAsset". 3 | 4 | These files will be deployed with your package and will be accessible using Android's 5 | AssetManager, like this: 6 | 7 | public class ReadAsset : Activity 8 | { 9 | protected override void OnCreate (Bundle bundle) 10 | { 11 | base.OnCreate (bundle); 12 | 13 | InputStream input = Assets.Open ("my_asset.txt"); 14 | } 15 | } 16 | 17 | Additionally, some Android functions will automatically load asset files: 18 | 19 | Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); 20 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/BootBroadcastReceiver.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Sergio Hernandez. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). 4 | // You may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | using Android; 17 | using Android.App; 18 | using Android.Content; 19 | using Microsoft.Maui.Storage; 20 | using XamarinForms.LocationService.Utils; 21 | 22 | [assembly: UsesPermission(Manifest.Permission.ReceiveBootCompleted)] 23 | namespace XamarinForms.LocationService.Droid; 24 | 25 | [BroadcastReceiver(Name = "com.locationservice.app.BootBroadcastReceiver", Enabled = true, Exported = true)] 26 | [IntentFilter([Intent.ActionBootCompleted])] 27 | public class BootBroadcastReceiver : BroadcastReceiver 28 | { 29 | public override void OnReceive(Context context, Intent intent) 30 | { 31 | if (intent.Action.Equals(Intent.ActionBootCompleted) && Preferences.Default.Get(Constants.SERVICE_STATUS_KEY, false)) 32 | { 33 | Intent main = new(context, typeof(MainActivity)); 34 | main.AddFlags(ActivityFlags.NewTask); 35 | context.StartActivity(main); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/CurrentActivityUtil.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Sergio Hernandez. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). 4 | // You may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | using System.Collections.Generic; 17 | using System.Linq; 18 | using Android.App; 19 | using Android.Runtime; 20 | using Android.Util; 21 | using Java.Lang; 22 | using Java.Util; 23 | 24 | namespace XamarinForms.LocationService.Android; 25 | 26 | internal static class CurrentActivityUtil 27 | { 28 | public static Activity GetCurrentActivity() 29 | { 30 | Activity activity = null; 31 | List objects = null; 32 | 33 | var activityThreadClass = Class.ForName("android.app.ActivityThread"); 34 | var activityThread = activityThreadClass.GetMethod("currentActivityThread").Invoke(null); 35 | var activityFields = activityThreadClass.GetDeclaredField("mActivities"); 36 | activityFields.Accessible = true; 37 | 38 | var obj = activityFields.Get(activityThread); 39 | 40 | if (obj is JavaDictionary) 41 | { 42 | var activities = (JavaDictionary)obj; 43 | objects = new List(activities.Values.Cast().ToList()); 44 | } 45 | else if (obj is ArrayMap) 46 | { 47 | var activities = (ArrayMap)obj; 48 | objects = new List(activities.Values().Cast().ToList()); 49 | } 50 | else if (obj is IMap) 51 | { 52 | var activities = (IMap)activityFields.Get(activityThread); 53 | objects = new List(activities.Values().Cast().ToList()); 54 | } 55 | 56 | if (objects != null && objects.Any()) 57 | { 58 | foreach (var activityRecord in objects) 59 | { 60 | var activityRecordClass = activityRecord.Class; 61 | var pausedField = activityRecordClass.GetDeclaredField("paused"); 62 | pausedField.Accessible = true; 63 | 64 | if (!pausedField.GetBoolean(activityRecord)) 65 | { 66 | var activityField = activityRecordClass.GetDeclaredField("activity"); 67 | activityField.Accessible = true; 68 | activity = (Activity)activityField.Get(activityRecord); 69 | break; 70 | } 71 | } 72 | } 73 | 74 | return activity; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Helpers/INotification.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Sergio Hernandez. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). 4 | // You may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | using Android.App; 17 | 18 | namespace XamarinForms.LocationService.Droid.Helpers; 19 | 20 | public interface INotification 21 | { 22 | Notification ReturnNotification(); 23 | } -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Helpers/NotificationHelper.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Sergio Hernandez. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). 4 | // You may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | using Android.App; 17 | using Android.Content; 18 | using Android.OS; 19 | 20 | namespace XamarinForms.LocationService.Droid.Helpers 21 | { 22 | using AndroidX.Core.App; 23 | 24 | internal class NotificationHelper : INotification 25 | { 26 | private static readonly string foregroundChannelId = "MyForegroundChannelId"; 27 | private static readonly Context context = Application.Context; 28 | 29 | public Notification ReturnNotification() 30 | { 31 | var intent = new Intent(context, typeof(MainActivity)); 32 | intent.AddFlags(ActivityFlags.SingleTop); 33 | 34 | var pendingIntent = PendingIntent.GetActivity(context, 0, intent, PendingIntentFlags.Immutable); 35 | 36 | var notifBuilder = new NotificationCompat.Builder(context, foregroundChannelId) 37 | .SetContentTitle("Your Title") 38 | .SetContentText("Your Message") 39 | .SetSmallIcon(Resource.Drawable.location) 40 | .SetOngoing(true) 41 | .SetContentIntent(pendingIntent); 42 | 43 | if (Build.VERSION.SdkInt >= BuildVersionCodes.O) 44 | { 45 | var notificationChannel = new NotificationChannel(foregroundChannelId, "Title", NotificationImportance.High) 46 | { 47 | Importance = NotificationImportance.High 48 | }; 49 | notificationChannel.EnableLights(true); 50 | notificationChannel.EnableVibration(true); 51 | notificationChannel.SetShowBadge(true); 52 | notificationChannel.SetVibrationPattern([100, 200, 300]); 53 | 54 | if (context.GetSystemService(Context.NotificationService) is NotificationManager notifManager) 55 | { 56 | notifBuilder.SetChannelId(foregroundChannelId); 57 | notifManager.CreateNotificationChannel(notificationChannel); 58 | } 59 | } 60 | 61 | return notifBuilder.Build(); 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/MainActivity.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Sergio Hernandez. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). 4 | // You may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | using Android.App; 17 | using Android.Content.PM; 18 | using Android.OS; 19 | using Android.Content; 20 | using Android.Provider; 21 | 22 | namespace XamarinForms.LocationService.Droid; 23 | 24 | using CommunityToolkit.Mvvm.Messaging; 25 | using XamarinForms.LocationService.Droid.Services; 26 | using XamarinForms.LocationService.Messages; 27 | using XamarinForms.LocationService.Utils; 28 | 29 | [Activity(Label = "XamarinForms.LocationService", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )] 30 | public class MainActivity : Microsoft.Maui.MauiAppCompatActivity 31 | { 32 | Intent serviceIntent; 33 | private const int RequestCode = 5469; 34 | protected override void OnCreate(Bundle savedInstanceState) 35 | { 36 | base.OnCreate(savedInstanceState); 37 | 38 | serviceIntent = new Intent(this, typeof(AndroidLocationService)); 39 | WeakReferenceMessenger.Default.Register(this, HandleServiceMessage); 40 | 41 | if (Build.VERSION.SdkInt >= BuildVersionCodes.M && !Settings.CanDrawOverlays(this)) 42 | { 43 | var intent = new Intent(Settings.ActionManageOverlayPermission); 44 | intent.SetFlags(ActivityFlags.NewTask); 45 | StartActivity(intent); 46 | } 47 | } 48 | 49 | private void HandleServiceMessage(object recipient, ServiceMessage message) 50 | { 51 | if (message.Value == ActionsEnum.START) 52 | { 53 | if (!IsServiceRunning(typeof(AndroidLocationService))) 54 | { 55 | if (Build.VERSION.SdkInt >= BuildVersionCodes.O) 56 | { 57 | StartForegroundService(serviceIntent); 58 | } 59 | else 60 | { 61 | StartService(serviceIntent); 62 | } 63 | } 64 | } 65 | else 66 | { 67 | if (IsServiceRunning(typeof(AndroidLocationService))) 68 | StopService(serviceIntent); 69 | } 70 | } 71 | 72 | public bool IsServiceRunning(System.Type serviceClass) 73 | { 74 | var manager = (ActivityManager)GetSystemService(ActivityService); 75 | foreach (var service in manager.GetRunningServices(int.MaxValue)) 76 | { 77 | if (service.Service.ClassName.Equals(Java.Lang.Class.FromType(serviceClass).CanonicalName)) 78 | { 79 | return true; 80 | } 81 | } 82 | return false; 83 | } 84 | 85 | protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) 86 | { 87 | if (requestCode == RequestCode) 88 | { 89 | if (Settings.CanDrawOverlays(this)) 90 | { 91 | 92 | } 93 | } 94 | 95 | base.OnActivityResult(requestCode, resultCode, data); 96 | } 97 | } -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/MainApplication.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Sergio Hernandez. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). 4 | // You may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | using System; 17 | using Android.App; 18 | using Android.Runtime; 19 | using Microsoft.Maui; 20 | using Microsoft.Maui.Controls; 21 | using Microsoft.Maui.Hosting; 22 | using XamarinForms.LocationService.Droid.Helpers; 23 | 24 | namespace XamarinForms.LocationService.Droid 25 | { 26 | [Application] 27 | public class MainApplication : MauiApplication 28 | { 29 | public MainApplication(IntPtr handle, JniHandleOwnership ownership) 30 | : base(handle, ownership) 31 | { 32 | DependencyService.Register(); 33 | DependencyService.Register(); 34 | } 35 | 36 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/PermissionConsent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Sergio Hernandez. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). 4 | // You may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | using System.Threading.Tasks; 17 | using Android; 18 | using Android.App; 19 | using Android.Content.PM; 20 | using AndroidX.Core.App; 21 | using AndroidX.Core.Content; 22 | using Microsoft.Maui.ApplicationModel; 23 | using XamarinForms.LocationService.Android; 24 | 25 | namespace XamarinForms.LocationService.Droid; 26 | 27 | public class PermissionConsent : IPermissionConsent 28 | { 29 | public async Task GetLocationConsent() 30 | { 31 | var status = await Permissions.CheckStatusAsync(); 32 | if (status == PermissionStatus.Denied || status == PermissionStatus.Unknown) 33 | { 34 | status = await Permissions.RequestAsync(); 35 | } 36 | 37 | if (status == PermissionStatus.Granted) 38 | { 39 | status = await Permissions.CheckStatusAsync(); 40 | if (status == PermissionStatus.Denied || status == PermissionStatus.Unknown) 41 | { 42 | await Permissions.RequestAsync(); 43 | } 44 | } 45 | } 46 | public void GetNotificationsConsent() 47 | { 48 | var context = Application.Context; 49 | var activity = CurrentActivityUtil.GetCurrentActivity(); 50 | if (ContextCompat.CheckSelfPermission(context, Manifest.Permission.PostNotifications) != Permission.Granted) 51 | { 52 | ActivityCompat.RequestPermissions(activity, [Manifest.Permission.PostNotifications], 0); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Properties/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 5 | 6 | 7 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Sergio Hernandez. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). 4 | // You may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | using System.Reflection; 17 | using System.Runtime.CompilerServices; 18 | using System.Runtime.InteropServices; 19 | using Android.App; 20 | [assembly: AssemblyTrademark("")] 21 | [assembly: AssemblyCulture("")] 22 | [assembly: ComVisible(false)] 23 | 24 | // Add some common permissions, these can be removed if not needed 25 | [assembly: UsesPermission(Android.Manifest.Permission.Internet)] 26 | [assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)] 27 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Resources/AboutResources.txt: -------------------------------------------------------------------------------- 1 | Images, layout descriptions, binary blobs and string dictionaries can be included 2 | in your application as resource files. Various Android APIs are designed to 3 | operate on the resource IDs instead of dealing with images, strings or binary blobs 4 | directly. 5 | 6 | For example, a sample Android app that contains a user interface layout (main.xml), 7 | an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) 8 | would keep its resources in the "Resources" directory of the application: 9 | 10 | Resources/ 11 | drawable-hdpi/ 12 | icon.png 13 | 14 | drawable-ldpi/ 15 | icon.png 16 | 17 | drawable-mdpi/ 18 | icon.png 19 | 20 | layout/ 21 | main.xml 22 | 23 | values/ 24 | strings.xml 25 | 26 | In order to get the build system to recognize Android resources, set the build action to 27 | "AndroidResource". The native Android APIs do not operate directly with filenames, but 28 | instead operate on resource IDs. When you compile an Android application that uses resources, 29 | the build system will package the resources for distribution and generate a class called 30 | "Resource" that contains the tokens for each one of the resources included. For example, 31 | for the above Resources layout, this is what the Resource class would expose: 32 | 33 | public class Resource { 34 | public class drawable { 35 | public const int icon = 0x123; 36 | } 37 | 38 | public class layout { 39 | public const int main = 0x456; 40 | } 41 | 42 | public class strings { 43 | public const int first_string = 0xabc; 44 | public const int second_string = 0xbcd; 45 | } 46 | } 47 | 48 | You would then use R.drawable.icon to reference the drawable/icon.png file, or Resource.layout.main 49 | to reference the layout/main.xml file, or Resource.strings.first_string to reference the first 50 | string in the dictionary file values/strings.xml. 51 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Resources/drawable/location.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.Android/Resources/drawable/location.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Resources/layout/Tabbar.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Resources/layout/Toolbar.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Resources/mipmap-anydpi-v26/icon.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Resources/mipmap-anydpi-v26/icon_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Resources/mipmap-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.Android/Resources/mipmap-hdpi/icon.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Resources/mipmap-hdpi/launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.Android/Resources/mipmap-hdpi/launcher_foreground.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Resources/mipmap-mdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.Android/Resources/mipmap-mdpi/icon.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Resources/mipmap-mdpi/launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.Android/Resources/mipmap-mdpi/launcher_foreground.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Resources/mipmap-xhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.Android/Resources/mipmap-xhdpi/icon.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Resources/mipmap-xhdpi/launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.Android/Resources/mipmap-xhdpi/launcher_foreground.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Resources/mipmap-xxhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.Android/Resources/mipmap-xxhdpi/icon.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Resources/mipmap-xxhdpi/launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.Android/Resources/mipmap-xxhdpi/launcher_foreground.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Resources/mipmap-xxxhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.Android/Resources/mipmap-xxxhdpi/icon.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Resources/mipmap-xxxhdpi/launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.Android/Resources/mipmap-xxxhdpi/launcher_foreground.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Resources/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFFFFF 4 | #3F51B5 5 | #303F9F 6 | #FF4081 7 | 8 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Resources/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/Services/AndroidLocationService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Sergio Hernandez. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). 4 | // You may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | using Android.OS; 17 | using Android.App; 18 | using Android.Content; 19 | 20 | namespace XamarinForms.LocationService.Droid.Services 21 | { 22 | using System.Threading.Tasks; 23 | 24 | using System.Threading; 25 | using XamarinForms.LocationService.Services; 26 | using XamarinForms.LocationService.Messages; 27 | using XamarinForms.LocationService.Droid.Helpers; 28 | using Microsoft.Maui.Controls; 29 | using CommunityToolkit.Mvvm.Messaging; 30 | using XamarinForms.LocationService.Utils; 31 | using global::Android.Content.PM; 32 | 33 | [Service(ForegroundServiceType = ForegroundService.TypeLocation)] 34 | public class AndroidLocationService : Service 35 | { 36 | CancellationTokenSource _cts; 37 | public const int SERVICE_RUNNING_NOTIFICATION_ID = 10000; 38 | 39 | public override IBinder OnBind(Intent intent) 40 | { 41 | return null; 42 | } 43 | 44 | public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) 45 | { 46 | _cts = new CancellationTokenSource(); 47 | 48 | var notification = DependencyService.Get().ReturnNotification(); 49 | if (Build.VERSION.SdkInt > BuildVersionCodes.Q) 50 | { 51 | StartForeground(SERVICE_RUNNING_NOTIFICATION_ID, notification, 52 | ForegroundService.TypeLocation); 53 | } 54 | else 55 | { 56 | StartForeground(SERVICE_RUNNING_NOTIFICATION_ID, notification); 57 | } 58 | 59 | Task.Run(() => { 60 | try 61 | { 62 | var locShared = new Location(); 63 | locShared.Run(_cts.Token).Wait(); 64 | } 65 | catch (OperationCanceledException) 66 | { 67 | } 68 | finally 69 | { 70 | if (_cts.IsCancellationRequested) 71 | { 72 | WeakReferenceMessenger.Default.Send(new ServiceMessage(ActionsEnum.STOP)); 73 | } 74 | } 75 | }, _cts.Token); 76 | 77 | return StartCommandResult.Sticky; 78 | } 79 | 80 | public override void OnDestroy() 81 | { 82 | if (_cts != null) 83 | { 84 | _cts.Token.ThrowIfCancellationRequested(); 85 | _cts.Cancel(); 86 | } 87 | base.OnDestroy(); 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /XamarinForms.LocationService.Android/XamarinForms.LocationService.Android.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Exe 4 | True 5 | Resources\Resource.designer.cs 6 | Resource 7 | Properties\AndroidManifest.xml 8 | Resources 9 | Assets 10 | false 11 | true 12 | true 13 | Xamarin.Android.Net.AndroidClientHandler 14 | net8.0-android34.0 15 | True 16 | XamarinForms.LocationService.Android 17 | XamarinForms.LocationService.Android 18 | Copyright © 2014 19 | 1.0.0.0 20 | 1.0.0.0 21 | 21.0 22 | 23 | 24 | None 25 | 26 | 27 | true 28 | false 29 | true 30 | C:\Users\Sergio Hernandez\AppData\Local\Xamarin\Mono for Android\Keystore\LocationService\LocationService.keystore 31 | LocationService 32 | LocationService 33 | LocationService 34 | 35 | 36 | 37 | 38 | 1.13.0.1 39 | 40 | 41 | 1.2.1.5 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/AppDelegate.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Sergio Hernandez. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). 4 | // You may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | namespace XamarinForms.LocationService.iOS 17 | { 18 | using CommunityToolkit.Mvvm.Messaging; 19 | using CoreLocation; 20 | using Foundation; 21 | using Microsoft.Maui.Controls; 22 | using Microsoft.Maui.Hosting; 23 | using System; 24 | using UIKit; 25 | using XamarinForms.LocationService.iOS.Services; 26 | using XamarinForms.LocationService.Messages; 27 | using XamarinForms.LocationService.Utils; 28 | 29 | [Register("AppDelegate")] 30 | public partial class AppDelegate : Microsoft.Maui.MauiUIApplicationDelegate 31 | { 32 | private nint backgroundTaskId; 33 | private iOsLocationService locationService; 34 | private readonly CLLocationManager locMgr = new(); 35 | public override bool FinishedLaunching(UIApplication app, NSDictionary options) 36 | { 37 | locationService = new iOsLocationService(); 38 | WeakReferenceMessenger.Default.Register(this, HandleServiceMessage); 39 | UIApplication.SharedApplication.SetMinimumBackgroundFetchInterval(UIApplication.BackgroundFetchIntervalMinimum); 40 | 41 | //Background Location Permissions 42 | if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) 43 | { 44 | locMgr.RequestAlwaysAuthorization(); 45 | } 46 | 47 | if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0)) 48 | { 49 | locMgr.AllowsBackgroundLocationUpdates = true; 50 | } 51 | 52 | DependencyService.Register(); 53 | 54 | return base.FinishedLaunching(app, options); 55 | } 56 | 57 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 58 | 59 | public override void OnResignActivation(UIApplication uiApplication) 60 | { 61 | base.OnResignActivation(uiApplication); 62 | 63 | // Request a background task to keep the app running in the background. 64 | backgroundTaskId = UIApplication.SharedApplication.BeginBackgroundTask(() => { 65 | // Perform cleanup operations when the background task is about to expire. 66 | UIApplication.SharedApplication.EndBackgroundTask(backgroundTaskId); 67 | backgroundTaskId = nint.MinValue; 68 | }); 69 | } 70 | 71 | public override void DidEnterBackground(UIApplication uiApplication) 72 | { 73 | base.DidEnterBackground(uiApplication); 74 | 75 | // Continue executing the background task. 76 | if (backgroundTaskId != nint.MinValue) 77 | { 78 | // Your app is currently running a background task. 79 | // Keep the app running in the background for as long as possible. 80 | UIApplication.SharedApplication.EndBackgroundTask(backgroundTaskId); 81 | backgroundTaskId = UIApplication.SharedApplication.BeginBackgroundTask(() => { 82 | // Perform cleanup operations when the background task is about to expire. 83 | UIApplication.SharedApplication.EndBackgroundTask(backgroundTaskId); 84 | backgroundTaskId = nint.MinValue; 85 | }); 86 | } 87 | } 88 | 89 | private async void HandleServiceMessage(object recipient, ServiceMessage message) 90 | { 91 | if (message.Value == ActionsEnum.START) 92 | { 93 | if (!locationService.isStarted) 94 | await locationService.Start(); 95 | } 96 | else 97 | { 98 | if (locationService.isStarted) 99 | locationService.Stop(); 100 | } 101 | } 102 | 103 | public override void PerformFetch(UIApplication application, Action completionHandler) 104 | { 105 | try 106 | { 107 | completionHandler(UIBackgroundFetchResult.NewData); 108 | } 109 | catch (Exception) 110 | { 111 | completionHandler(UIBackgroundFetchResult.NoData); 112 | } 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images": [ 3 | { 4 | "scale": "2x", 5 | "size": "20x20", 6 | "idiom": "iphone", 7 | "filename": "Icon40.png" 8 | }, 9 | { 10 | "scale": "3x", 11 | "size": "20x20", 12 | "idiom": "iphone", 13 | "filename": "Icon60.png" 14 | }, 15 | { 16 | "scale": "2x", 17 | "size": "29x29", 18 | "idiom": "iphone", 19 | "filename": "Icon58.png" 20 | }, 21 | { 22 | "scale": "3x", 23 | "size": "29x29", 24 | "idiom": "iphone", 25 | "filename": "Icon87.png" 26 | }, 27 | { 28 | "scale": "2x", 29 | "size": "40x40", 30 | "idiom": "iphone", 31 | "filename": "Icon80.png" 32 | }, 33 | { 34 | "scale": "3x", 35 | "size": "40x40", 36 | "idiom": "iphone", 37 | "filename": "Icon120.png" 38 | }, 39 | { 40 | "scale": "2x", 41 | "size": "60x60", 42 | "idiom": "iphone", 43 | "filename": "Icon120.png" 44 | }, 45 | { 46 | "scale": "3x", 47 | "size": "60x60", 48 | "idiom": "iphone", 49 | "filename": "Icon180.png" 50 | }, 51 | { 52 | "scale": "1x", 53 | "size": "20x20", 54 | "idiom": "ipad", 55 | "filename": "Icon20.png" 56 | }, 57 | { 58 | "scale": "2x", 59 | "size": "20x20", 60 | "idiom": "ipad", 61 | "filename": "Icon40.png" 62 | }, 63 | { 64 | "scale": "1x", 65 | "size": "29x29", 66 | "idiom": "ipad", 67 | "filename": "Icon29.png" 68 | }, 69 | { 70 | "scale": "2x", 71 | "size": "29x29", 72 | "idiom": "ipad", 73 | "filename": "Icon58.png" 74 | }, 75 | { 76 | "scale": "1x", 77 | "size": "40x40", 78 | "idiom": "ipad", 79 | "filename": "Icon40.png" 80 | }, 81 | { 82 | "scale": "2x", 83 | "size": "40x40", 84 | "idiom": "ipad", 85 | "filename": "Icon80.png" 86 | }, 87 | { 88 | "scale": "1x", 89 | "size": "76x76", 90 | "idiom": "ipad", 91 | "filename": "Icon76.png" 92 | }, 93 | { 94 | "scale": "2x", 95 | "size": "76x76", 96 | "idiom": "ipad", 97 | "filename": "Icon152.png" 98 | }, 99 | { 100 | "scale": "2x", 101 | "size": "83.5x83.5", 102 | "idiom": "ipad", 103 | "filename": "Icon167.png" 104 | }, 105 | { 106 | "scale": "1x", 107 | "size": "1024x1024", 108 | "idiom": "ios-marketing", 109 | "filename": "Icon1024.png" 110 | } 111 | ], 112 | "properties": {}, 113 | "info": { 114 | "version": 1, 115 | "author": "xcode" 116 | } 117 | } -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon1024.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon120.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon152.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon167.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon167.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon180.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon20.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon29.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon40.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon58.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon58.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon60.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon76.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon80.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon80.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon87.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.iOS/Assets.xcassets/AppIcon.appiconset/Icon87.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Entitlements.plist: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UIDeviceFamily 6 | 7 | 1 8 | 2 9 | 10 | UISupportedInterfaceOrientations 11 | 12 | UIInterfaceOrientationPortrait 13 | UIInterfaceOrientationLandscapeLeft 14 | UIInterfaceOrientationLandscapeRight 15 | 16 | UISupportedInterfaceOrientations~ipad 17 | 18 | UIInterfaceOrientationPortrait 19 | UIInterfaceOrientationPortraitUpsideDown 20 | UIInterfaceOrientationLandscapeLeft 21 | UIInterfaceOrientationLandscapeRight 22 | 23 | MinimumOSVersion 24 | 8.0 25 | CFBundleDisplayName 26 | XamarinForms.LocationService 27 | CFBundleIdentifier 28 | com.companyname.XamarinForms.LocationService 29 | CFBundleVersion 30 | 1.0 31 | UILaunchStoryboardName 32 | LaunchScreen 33 | CFBundleName 34 | XamarinForms.LocationService 35 | XSAppIconAssets 36 | Assets.xcassets/AppIcon.appiconset 37 | UIBackgroundModes 38 | 39 | location 40 | fetch 41 | processing 42 | 43 | NSLocationWhenInUseUsageDescription 44 | These permissions are needed to give get the most accurate location of your device. 45 | NSLocationAlwaysUsageDescription 46 | These permissions are needed to give get the most accurate location of your device. 47 | NSLocationAlwaysAndWhenInUseUsageDescription 48 | These permissions are needed to give get the most accurate location of your device. 49 | 50 | 51 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/LocationManager.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Sergio Hernandez. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). 4 | // You may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | using System; 17 | using CoreLocation; 18 | using UIKit; 19 | 20 | namespace XamarinForms.LocationService.iOS; 21 | 22 | public class LocationManager 23 | { 24 | protected CLLocationManager locMgr; 25 | public event EventHandler LocationUpdated = delegate { }; 26 | 27 | public LocationManager() 28 | { 29 | this.locMgr = new CLLocationManager 30 | { 31 | PausesLocationUpdatesAutomatically = false 32 | }; 33 | 34 | if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) 35 | { 36 | locMgr.RequestAlwaysAuthorization(); 37 | } 38 | 39 | if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0)) 40 | { 41 | locMgr.AllowsBackgroundLocationUpdates = true; 42 | } 43 | } 44 | 45 | public CLLocationManager LocMgr 46 | { 47 | get { return this.locMgr; } 48 | } 49 | 50 | public void StartLocationUpdates() 51 | { 52 | if (CLLocationManager.LocationServicesEnabled) 53 | { 54 | LocMgr.DesiredAccuracy = 1; 55 | LocMgr.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => 56 | { 57 | LocationUpdated(this, new LocationUpdatedEventArgs(e.Locations[e.Locations.Length - 1])); 58 | }; 59 | LocMgr.StartUpdatingLocation(); 60 | } 61 | } 62 | } 63 | 64 | public class LocationUpdatedEventArgs(CLLocation location) : EventArgs 65 | { 66 | public CLLocation Location 67 | { 68 | get { return location; } 69 | } 70 | } -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Main.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Sergio Hernandez. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). 4 | // You may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | namespace XamarinForms.LocationService.iOS; 17 | 18 | using UIKit; 19 | 20 | public class Application 21 | { 22 | // This is the main entry point of the application. 23 | static void Main(string[] args) 24 | { 25 | // if you want to use a different Application Delegate class from "AppDelegate" 26 | // you can specify it here. 27 | UIApplication.Main(args, null, typeof(AppDelegate)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/PermissionConsent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Sergio Hernandez. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). 4 | // You may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | using CoreLocation; 17 | using System.Threading.Tasks; 18 | using UIKit; 19 | 20 | namespace XamarinForms.LocationService.iOS; 21 | 22 | public class PermissionConsent : IPermissionConsent 23 | { 24 | public static LocationManager Manager { get; set; } 25 | public PermissionConsent() 26 | { 27 | Manager = new LocationManager(); 28 | Manager.StartLocationUpdates(); 29 | } 30 | public async Task GetLocationConsent() 31 | { 32 | var manager = new CLLocationManager(); 33 | manager.AuthorizationChanged += (sender, args) => { 34 | //Console.WriteLine("Authorization changed to: {0}", args.Status); 35 | }; 36 | if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) 37 | { 38 | manager.RequestAlwaysAuthorization(); 39 | } 40 | } 41 | 42 | public void GetNotificationsConsent() { } 43 | } -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Sergio Hernandez. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). 4 | // You may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | using System.Reflection; 17 | using System.Runtime.CompilerServices; 18 | using System.Runtime.InteropServices; 19 | [assembly: AssemblyTrademark("")] 20 | [assembly: AssemblyCulture("")] 21 | 22 | // Setting ComVisible to false makes the types in this assembly not visible 23 | // to COM components. If you need to access a type in this assembly from 24 | // COM, set the ComVisible attribute to true on that type. 25 | [assembly: ComVisible(false)] 26 | 27 | // The following GUID is for the ID of the typelib if this project is exposed to COM 28 | [assembly: Guid("72bdc44f-c588-44f3-b6df-9aace7daafdd")] 29 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Resources/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.iOS/Resources/Default-568h@2x.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Resources/Default-Portrait.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.iOS/Resources/Default-Portrait.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Resources/Default-Portrait@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.iOS/Resources/Default-Portrait@2x.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Resources/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.iOS/Resources/Default.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Resources/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shernandezp/XamarinForms.LocationService/0e8ee7259aa07cb8101891fa63d2c5d4ffbe33db/XamarinForms.LocationService.iOS/Resources/Default@2x.png -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Resources/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/Services/iOsLocationService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Sergio Hernandez. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). 4 | // You may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | using System; 17 | using System.Threading; 18 | using System.Threading.Tasks; 19 | using UIKit; 20 | using XamarinForms.LocationService.Messages; 21 | using XamarinForms.LocationService.Services; 22 | using CommunityToolkit.Mvvm.Messaging; 23 | using XamarinForms.LocationService.Utils; 24 | 25 | namespace XamarinForms.LocationService.iOS.Services; 26 | 27 | public class iOsLocationService 28 | { 29 | nint _taskId; 30 | CancellationTokenSource _cts; 31 | public bool isStarted = false; 32 | 33 | public async Task Start() 34 | { 35 | _cts = new CancellationTokenSource(); 36 | _taskId = UIApplication.SharedApplication.BeginBackgroundTask("com.company.product.name", OnExpiration); 37 | 38 | try 39 | { 40 | var locShared = new Location(); 41 | isStarted = true; 42 | await locShared.Run(_cts.Token); 43 | 44 | } 45 | catch (OperationCanceledException) 46 | { 47 | } 48 | finally 49 | { 50 | if (_cts.IsCancellationRequested) 51 | { 52 | WeakReferenceMessenger.Default.Send(new ServiceMessage(ActionsEnum.STOP)); 53 | } 54 | } 55 | 56 | var time = UIApplication.SharedApplication.BackgroundTimeRemaining; 57 | 58 | UIApplication.SharedApplication.EndBackgroundTask(_taskId); 59 | } 60 | 61 | public void Stop() 62 | { 63 | isStarted = false; 64 | _cts.Cancel(); 65 | } 66 | 67 | void OnExpiration() 68 | { 69 | UIApplication.SharedApplication.EndBackgroundTask(_taskId); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.iOS/XamarinForms.LocationService.iOS.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Exe 4 | Resources 5 | true 6 | manual 7 | net8.0-ios 8 | True 9 | XamarinForms.LocationService.iOS 10 | XamarinForms.LocationService.iOS 11 | Copyright © 2014 12 | 1.0.0.0 13 | 1.0.0.0 14 | 15 | 16 | None 17 | true 18 | iossimulator-x64 19 | 20 | 21 | None 22 | iossimulator-x64 23 | 24 | 25 | iPhone Developer 26 | true 27 | Entitlements.plist 28 | None 29 | -all 30 | ios-arm64 31 | 32 | 33 | iPhone Developer 34 | Entitlements.plist 35 | ios-arm64 36 | 37 | 38 | 39 | true 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /XamarinForms.LocationService.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio Version 17 3 | VisualStudioVersion = 17.9.34701.34 4 | MinimumVisualStudioVersion = 10.0.40219.1 5 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XamarinForms.LocationService", "XamarinForms.LocationService\XamarinForms.LocationService.csproj", "{A22289B2-5F1A-4F3E-A1E4-F84028F829D4}" 6 | EndProject 7 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XamarinForms.LocationService.Android", "XamarinForms.LocationService.Android\XamarinForms.LocationService.Android.csproj", "{32D4F158-763D-431C-8F1B-B4360888B1F9}" 8 | EndProject 9 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XamarinForms.LocationService.iOS", "XamarinForms.LocationService.iOS\XamarinForms.LocationService.iOS.csproj", "{A9063D7F-9847-4FBA-A6FD-6C676EB190B3}" 10 | EndProject 11 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{233E5491-4470-48D0-8CE3-B564DF101462}" 12 | ProjectSection(SolutionItems) = preProject 13 | .editorconfig = .editorconfig 14 | README.md = README.md 15 | EndProjectSection 16 | EndProject 17 | Global 18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 19 | Debug|Any CPU = Debug|Any CPU 20 | Debug|iPhone = Debug|iPhone 21 | Debug|iPhoneSimulator = Debug|iPhoneSimulator 22 | Release|Any CPU = Release|Any CPU 23 | Release|iPhone = Release|iPhone 24 | Release|iPhoneSimulator = Release|iPhoneSimulator 25 | EndGlobalSection 26 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 27 | {A22289B2-5F1A-4F3E-A1E4-F84028F829D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 28 | {A22289B2-5F1A-4F3E-A1E4-F84028F829D4}.Debug|Any CPU.Build.0 = Debug|Any CPU 29 | {A22289B2-5F1A-4F3E-A1E4-F84028F829D4}.Debug|iPhone.ActiveCfg = Debug|Any CPU 30 | {A22289B2-5F1A-4F3E-A1E4-F84028F829D4}.Debug|iPhone.Build.0 = Debug|Any CPU 31 | {A22289B2-5F1A-4F3E-A1E4-F84028F829D4}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU 32 | {A22289B2-5F1A-4F3E-A1E4-F84028F829D4}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU 33 | {A22289B2-5F1A-4F3E-A1E4-F84028F829D4}.Release|Any CPU.ActiveCfg = Release|Any CPU 34 | {A22289B2-5F1A-4F3E-A1E4-F84028F829D4}.Release|Any CPU.Build.0 = Release|Any CPU 35 | {A22289B2-5F1A-4F3E-A1E4-F84028F829D4}.Release|iPhone.ActiveCfg = Release|Any CPU 36 | {A22289B2-5F1A-4F3E-A1E4-F84028F829D4}.Release|iPhone.Build.0 = Release|Any CPU 37 | {A22289B2-5F1A-4F3E-A1E4-F84028F829D4}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU 38 | {A22289B2-5F1A-4F3E-A1E4-F84028F829D4}.Release|iPhoneSimulator.Build.0 = Release|Any CPU 39 | {32D4F158-763D-431C-8F1B-B4360888B1F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 40 | {32D4F158-763D-431C-8F1B-B4360888B1F9}.Debug|Any CPU.Build.0 = Debug|Any CPU 41 | {32D4F158-763D-431C-8F1B-B4360888B1F9}.Debug|Any CPU.Deploy.0 = Debug|Any CPU 42 | {32D4F158-763D-431C-8F1B-B4360888B1F9}.Debug|iPhone.ActiveCfg = Debug|Any CPU 43 | {32D4F158-763D-431C-8F1B-B4360888B1F9}.Debug|iPhone.Build.0 = Debug|Any CPU 44 | {32D4F158-763D-431C-8F1B-B4360888B1F9}.Debug|iPhone.Deploy.0 = Debug|Any CPU 45 | {32D4F158-763D-431C-8F1B-B4360888B1F9}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU 46 | {32D4F158-763D-431C-8F1B-B4360888B1F9}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU 47 | {32D4F158-763D-431C-8F1B-B4360888B1F9}.Debug|iPhoneSimulator.Deploy.0 = Debug|Any CPU 48 | {32D4F158-763D-431C-8F1B-B4360888B1F9}.Release|Any CPU.ActiveCfg = Release|Any CPU 49 | {32D4F158-763D-431C-8F1B-B4360888B1F9}.Release|Any CPU.Build.0 = Release|Any CPU 50 | {32D4F158-763D-431C-8F1B-B4360888B1F9}.Release|Any CPU.Deploy.0 = Release|Any CPU 51 | {32D4F158-763D-431C-8F1B-B4360888B1F9}.Release|iPhone.ActiveCfg = Release|Any CPU 52 | {32D4F158-763D-431C-8F1B-B4360888B1F9}.Release|iPhone.Build.0 = Release|Any CPU 53 | {32D4F158-763D-431C-8F1B-B4360888B1F9}.Release|iPhone.Deploy.0 = Release|Any CPU 54 | {32D4F158-763D-431C-8F1B-B4360888B1F9}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU 55 | {32D4F158-763D-431C-8F1B-B4360888B1F9}.Release|iPhoneSimulator.Build.0 = Release|Any CPU 56 | {32D4F158-763D-431C-8F1B-B4360888B1F9}.Release|iPhoneSimulator.Deploy.0 = Release|Any CPU 57 | {A9063D7F-9847-4FBA-A6FD-6C676EB190B3}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator 58 | {A9063D7F-9847-4FBA-A6FD-6C676EB190B3}.Debug|Any CPU.Build.0 = Debug|iPhoneSimulator 59 | {A9063D7F-9847-4FBA-A6FD-6C676EB190B3}.Debug|iPhone.ActiveCfg = Debug|iPhone 60 | {A9063D7F-9847-4FBA-A6FD-6C676EB190B3}.Debug|iPhone.Build.0 = Debug|iPhone 61 | {A9063D7F-9847-4FBA-A6FD-6C676EB190B3}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator 62 | {A9063D7F-9847-4FBA-A6FD-6C676EB190B3}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator 63 | {A9063D7F-9847-4FBA-A6FD-6C676EB190B3}.Release|Any CPU.ActiveCfg = Release|iPhoneSimulator 64 | {A9063D7F-9847-4FBA-A6FD-6C676EB190B3}.Release|iPhone.ActiveCfg = Release|iPhone 65 | {A9063D7F-9847-4FBA-A6FD-6C676EB190B3}.Release|iPhone.Build.0 = Release|iPhone 66 | {A9063D7F-9847-4FBA-A6FD-6C676EB190B3}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator 67 | {A9063D7F-9847-4FBA-A6FD-6C676EB190B3}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator 68 | EndGlobalSection 69 | GlobalSection(SolutionProperties) = preSolution 70 | HideSolutionNode = FALSE 71 | EndGlobalSection 72 | GlobalSection(ExtensibilityGlobals) = postSolution 73 | SolutionGuid = {F7DF0210-486D-4C43-A5F8-AFBBEC0874A8} 74 | EndGlobalSection 75 | EndGlobal 76 | -------------------------------------------------------------------------------- /XamarinForms.LocationService/App.xaml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /XamarinForms.LocationService/App.xaml.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Sergio Hernandez. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). 4 | // You may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | namespace XamarinForms.LocationService 17 | { 18 | public partial class App : Application 19 | { 20 | public App() 21 | { 22 | InitializeComponent(); 23 | 24 | MainPage = new MainPage(); 25 | } 26 | 27 | protected override void OnStart() 28 | { 29 | } 30 | 31 | protected override void OnSleep() 32 | { 33 | } 34 | 35 | protected override void OnResume() 36 | { 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /XamarinForms.LocationService/AppService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Sergio Hernandez. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). 4 | // You may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | namespace XamarinForms.LocationService; 17 | 18 | public static class AppService 19 | { 20 | public static object? GetService(Type serviceType) => Current?.GetService(serviceType); 21 | 22 | public static TService? GetService() => 23 | Current is null ? default : Current.GetService(); 24 | 25 | public static IServiceProvider? Current => 26 | IPlatformApplication.Current?.Services; 27 | } 28 | -------------------------------------------------------------------------------- /XamarinForms.LocationService/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Sergio Hernandez. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). 4 | // You may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | [assembly: XamlCompilation(XamlCompilationOptions.Compile)] -------------------------------------------------------------------------------- /XamarinForms.LocationService/IPermissionConsent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 Sergio Hernandez. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). 4 | // You may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | 16 | namespace XamarinForms.LocationService; 17 | 18 | using System.Threading.Tasks; 19 | 20 | public interface IPermissionConsent 21 | { 22 | Task GetLocationConsent(); 23 | void GetNotificationsConsent(); 24 | } 25 | -------------------------------------------------------------------------------- /XamarinForms.LocationService/MainPage.xaml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 |