Skip to content

Commit

Permalink
Add support for Deeplink for IOS (#1270)
Browse files Browse the repository at this point in the history
* Setup Deeplink for ios.

* Updated app_links.

* ios init method in session model

* Updated version.

* added geolookup OnRefresh.
  • Loading branch information
jigar-f authored Dec 20, 2024
1 parent 2377a8f commit 3bf1cd4
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 10 deletions.
21 changes: 19 additions & 2 deletions internalsdk/session_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/getlantern/lantern-client/internalsdk/auth"
"github.com/getlantern/lantern-client/internalsdk/common"
"github.com/getlantern/lantern-client/internalsdk/ios"
iosGeoLookup "github.com/getlantern/lantern-client/internalsdk/ios/geolookup"
"github.com/getlantern/lantern-client/internalsdk/pro"
"github.com/getlantern/lantern-client/internalsdk/protos"
"github.com/getlantern/pathdb"
Expand Down Expand Up @@ -186,13 +187,29 @@ func NewSessionModel(mdb minisql.DB, opts *SessionModelOpts) (*SessionModel, err

m.baseModel.doInvokeMethod = m.doInvokeMethod
if opts.Platform == "ios" {
go m.setupIosConfigure(opts.ConfigPath, int(userID), token, deviceID)
go m.iosInit(opts.ConfigPath, int(userID), token, deviceID)
}
log.Debugf("SessionModel initialized")
go m.initSessionModel(context.Background(), opts)
return m, nil
}

// this method initializes the ios configuration for the session model
// also this method check for geoLookup
func (m *SessionModel) iosInit(configPath string, userId int, token string, deviceId string) error {
go m.setupIosConfigure(configPath, userId, token, deviceId)
// go iosGeoLookup.Refresh()
go func() {
if <-iosGeoLookup.OnRefresh() {
country := iosGeoLookup.GetCountry(5 * time.Second)
//get the country for the user
log.Debugf("Getting country for user %v", country)
m.SetCountry(country)
}
}()
return nil
}

// setupIosConfigure sets up the iOS configuration for the session model.
// It continuously checks if the global configuration is available and retries every second if not.
func (m *SessionModel) setupIosConfigure(configPath string, userId int, token string, deviceId string) {
Expand Down Expand Up @@ -898,7 +915,6 @@ func (m *SessionModel) GetToken() (string, error) {
}

func (m *SessionModel) SetCountry(country string) error {
//Find better way to do it
return pathdb.Mutate(m.db, func(tx pathdb.TX) error {
return pathdb.Put(tx, pathGeoCountryCode, country, "")
})
Expand Down Expand Up @@ -1552,6 +1568,7 @@ func checkAdsEnabled(session *SessionModel) error {
return err
}
if isPro {
log.Debug("User is pro ads should be disabled")
return pathdb.Mutate(session.db, func(tx pathdb.TX) error {
return pathdb.Put[string](tx, pathShowAds, "", "")
})
Expand Down
6 changes: 6 additions & 0 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Flutter
import Internalsdk
import SQLite
import UIKit
import app_links

//know Issue
//  CFPrefsPlistSource<0x28281e580> (Domain: group.getlantern.lantern, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): Using kCFPreferencesAnyUser with a container is only allowed for System Containers,
Expand Down Expand Up @@ -34,6 +35,11 @@ import UIKit
print(exception.reason)
print(exception.callStackSymbols)
}
if let url = AppLinks.shared.getLink(launchOptions: launchOptions) {
// We have a link, propagate it to your Flutter app or not
AppLinks.shared.handleLink(url: url)
return true
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

Expand Down
8 changes: 6 additions & 2 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>8.0.2</string>
<string>8.0.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>50</string>
<string>51</string>
<key>LSApplicationCategoryType</key>
<string></string>
<key>CURRENT_SCHEME_NAME</key>
<string>$(CURRENT_SCHEME_NAME)</string>
<key>FlutterDeepLinkingEnabled</key>
<false/>
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-2685698271254859~9283700921</string>
<key>LSRequiresIPhoneOS</key>
Expand Down
5 changes: 5 additions & 0 deletions ios/Runner/Runner.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
<dict>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:lantern.io</string>
<string>webcredentials:lantern.io</string>
</array>
<key>com.apple.developer.networking.networkextension</key>
<array>
<string>packet-tunnel-provider</string>
Expand Down
8 changes: 4 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ packages:
dependency: "direct main"
description:
name: app_links
sha256: ad1a6d598e7e39b46a34f746f9a8b011ee147e4c275d407fa457e7a62f84dd99
sha256: "433df2e61b10519407475d7f69e470789d23d593f28224c38ba1068597be7950"
url: "https://pub.dev"
source: hosted
version: "6.3.2"
version: "6.3.3"
app_links_linux:
dependency: transitive
description:
Expand Down Expand Up @@ -880,10 +880,10 @@ packages:
dependency: "direct main"
description:
name: get_it
sha256: c49895c1ecb0ee2a0ec568d39de882e2c299ba26355aa6744ab1001f98cebd15
sha256: f126a3e286b7f5b578bf436d5592968706c4c1de28a228b870ce375d9f743103
url: "https://pub.dev"
source: hosted
version: "8.0.2"
version: "8.0.3"
gettext_parser:
dependency: transitive
description:
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ dependencies:
# Generate bindings to native libraries
ffi: ^2.1.3
# Deeplink handling
app_links: ^6.3.2
app_links: ^6.3.3
# Service Locator
get_it: ^8.0.2
get_it: ^8.0.3
#Loading
animated_loading_border: ^0.0.2
shimmer: ^3.0.0
Expand Down

0 comments on commit 3bf1cd4

Please sign in to comment.