Skip to content

Commit

Permalink
Merge pull request #68 from pwa-builder/gleb/iap-try
Browse files Browse the repository at this point in the history
Quality of life updates
  • Loading branch information
khmyznikov committed Feb 17, 2024
2 parents dba68cd + 3ea7802 commit 19d2ec8
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 129 deletions.
14 changes: 7 additions & 7 deletions Microsoft.PWABuilder.IOS.Web/Models/XcodePwaShellProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ private void UpdateAppColors()
var mainStoryboard = GetFile("Main.storyboard");

// Set the splash color.
var existingSplashColorLine = "{{PWABuilder.iOS.splashBgColor}}";
var desiredSplashColorLine = $"<color key=\"backgroundColor\" {options.SplashColor.ToStoryboardColorString()} alpha=\"1\" colorSpace=\"custom\" customColorSpace=\"sRGB\"/>";
launchScreenStoryboard.Replace(existingSplashColorLine, desiredSplashColorLine);
mainStoryboard.Replace(existingSplashColorLine, desiredSplashColorLine);
// var existingSplashColorLine = "{{PWABuilder.iOS.splashBgColor}}";
// var desiredSplashColorLine = $"<color key=\"backgroundColor\" {options.SplashColor.ToStoryboardColorString()} alpha=\"1\" colorSpace=\"custom\" customColorSpace=\"sRGB\"/>";
// launchScreenStoryboard.Replace(existingSplashColorLine, desiredSplashColorLine);
// mainStoryboard.Replace(existingSplashColorLine, desiredSplashColorLine);

// Set the status bar color
var existingStatusBarColorLine = "{{PWABuilder.iOS.statusBarColor}}";
var desiredStatusBarColorLine = $"<color key=\"backgroundColor\" {options.StatusBarColor.ToStoryboardColorString()} alpha=\"1\" colorSpace=\"custom\" customColorSpace=\"sRGB\"/>";
mainStoryboard.Replace(existingStatusBarColorLine, desiredStatusBarColorLine);
// var existingStatusBarColorLine = "{{PWABuilder.iOS.statusBarColor}}";
// var desiredStatusBarColorLine = $"<color key=\"backgroundColor\" {options.StatusBarColor.ToStoryboardColorString()} alpha=\"1\" colorSpace=\"custom\" customColorSpace=\"sRGB\"/>";
// mainStoryboard.Replace(existingStatusBarColorLine, desiredStatusBarColorLine);

// Set the progress var color
var existingProgressBarColorLine = "{{PWABuilder.iOS.progressBarColor}}";
Expand Down
10 changes: 9 additions & 1 deletion Microsoft.PWABuilder.IOS.Web/Resources/ios-project-src/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment the next line to define a global platform for your project
platform :ios, '13.0'
platform :ios, '15.0'

target 'pwa-shell' do
# Comment the next line if you don't want to use dynamic frameworks
Expand All @@ -9,3 +9,11 @@ target 'pwa-shell' do
pod 'Firebase/Messaging'

end

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.0'
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -351,7 +351,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand All @@ -375,8 +375,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = "pwa-shell/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
"IPHONEOS_DEPLOYMENT_TARGET[sdk=macosx*]" = 14.2;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -404,8 +403,7 @@
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = "pwa-shell/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
"IPHONEOS_DEPLOYMENT_TARGET[sdk=macosx*]" = 14.2;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

// TODO: if we're using Firebase, uncomment this
// TODO: if we're using Firebase, uncomment next string
//FirebaseApp.configure()

// [START set_messaging_delegate]
Expand All @@ -23,13 +23,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

UNUserNotificationCenter.current().delegate = self

// let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
// UNUserNotificationCenter.current().requestAuthorization(
// options: authOptions,
// completionHandler: {_, _ in })
//
//
// application.registerForRemoteNotifications()
// let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
// UNUserNotificationCenter.current().requestAuthorization(
// options: authOptions,
// completionHandler: {_, _ in })

// TODO: if we're using Firebase, uncomment next string
// application.registerForRemoteNotifications()

// [END register_for_notifications]
return true
Expand All @@ -39,7 +39,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification
// With swizzling disabled you must let Messaging know about the message, for Analytics
// Messaging.messaging().appDidReceiveMessage(userInfo)
// Print message ID.
Expand All @@ -56,7 +55,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification
// With swizzling disabled you must let Messaging know about the message, for Analytics
// Messaging.messaging().appDidReceiveMessage(userInfo)
// Print message ID.
Expand Down Expand Up @@ -107,7 +105,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
sendPushToWebView(userInfo: userInfo)

// Change this to your preferred presentation option
completionHandler([[.alert, .sound]])
completionHandler([[.banner, .list, .sound]])
}

func userNotificationCenter(_ center: UNUserNotificationCenter,
Expand Down Expand Up @@ -137,6 +135,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

let dataDict:[String: String] = ["token": fcmToken ?? ""]
NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
handleFCMToken()
// TODO: If necessary send token to application server.
// Note: This callback is fired at each app startup and whenever a new token is generated.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</imageView>
</subviews>
<viewLayoutGuide key="safeArea" id="XpK-Bq-A7U"/>
{{PWABuilder.iOS.splashBgColor}}
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="I2s-HW-Q4d" firstAttribute="centerY" secondItem="4mO-e4-REQ" secondAttribute="centerY" id="4kv-Qc-mPU"/>
<constraint firstItem="I2s-HW-Q4d" firstAttribute="centerX" secondItem="4mO-e4-REQ" secondAttribute="centerX" id="6Z0-rS-c8Q"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,33 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="DIO-mU-n27" userLabel="Loading View">
<rect key="frame" x="94" y="323" width="200" height="200"/>
<rect key="frame" x="95" y="322" width="200" height="200"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" image="LaunchIcon" translatesAutoresizingMaskIntoConstraints="NO" id="4oa-LZ-pgs">
<rect key="frame" x="66" y="70" width="69" height="61"/>
<rect key="frame" x="68" y="68" width="64" height="64"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<color key="tintColor" systemColor="secondarySystemFillColor"/>
<rect key="contentStretch" x="0.0" y="0.0" width="0.0" height="0.0"/>
</imageView>
<progressView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" progress="0.10000000000000001" id="xSD-dq-HF9">
<rect key="frame" x="50" y="146" width="100" height="15"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.5" colorSpace="custom" customColorSpace="sRGB"/>
<color key="backgroundColor" systemColor="secondarySystemFillColor"/>
{{PWABuilder.iOS.progressBarColor}}
</progressView>
<imageView hidden="YES" opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" image="wifi.slash" catalog="system" translatesAutoresizingMaskIntoConstraints="NO" id="TpV-I7-c6z">
<rect key="frame" x="85" y="159.33333333333314" width="31.999999999999886" height="30.000000000000085"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
{{PWABuilder.iOS.splashBgColor}}
<color key="tintColor" systemColor="secondaryLabelColor"/>
</imageView>
</subviews>
<viewLayoutGuide key="safeArea" id="a0B-Gx-0cO"/>
{{PWABuilder.iOS.splashBgColor}}
<rect key="contentStretch" x="0.0" y="0.0" width="0.0" height="0.0"/>
</view>
</subviews>
{{PWABuilder.iOS.splashBgColor}}
</view>
</subviews>
{{PWABuilder.iOS.statusBarColor}}
</view>
</subviews>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
Expand All @@ -66,7 +62,6 @@
<outlet property="connectionProblemView" destination="TpV-I7-c6z" id="76F-WR-UnJ"/>
<outlet property="loadingView" destination="DIO-mU-n27" id="Wlk-Yd-6b1"/>
<outlet property="progressView" destination="xSD-dq-HF9" id="0jL-XR-Xwq"/>
<outlet property="splashBkgView" destination="p0s-Fg-eGP" id="fMY-qQ-Qid"/>
<outlet property="webviewView" destination="PHY-vp-dMl" id="qhH-E4-3lf"/>
</connections>
</viewController>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,33 @@ func handlePushState() {
}
}

func checkViewAndEvaluate(event: String, detail: String) {
if (!PWAShell.webView.isHidden && !PWAShell.webView.isLoading ) {
DispatchQueue.main.async(execute: {
PWAShell.webView.evaluateJavaScript("this.dispatchEvent(new CustomEvent('\(event)', { detail: \(detail) }))")
})
}
else {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
checkViewAndEvaluate(event: event, detail: detail)
}
}
}

func handleFCMToken(){
DispatchQueue.main.async(execute: {
Messaging.messaging().token { token, error in
if let error = error {
print("Error fetching FCM registration token: \(error)")
checkViewAndEvaluate(event: "push-token", detail: "ERROR GET TOKEN")
} else if let token = token {
print("FCM registration token: \(token)")
checkViewAndEvaluate(event: "push-token", detail: token)
}
}
})
}

func sendPushToWebView(userInfo: [AnyHashable: Any]){
var json = "";
do {
Expand All @@ -142,17 +169,5 @@ func sendPushToWebView(userInfo: [AnyHashable: Any]){
print("ERROR: userInfo parsing problem")
return
}
func checkViewAndEvaluate() {
if (!PWAShell.webView.isHidden && !PWAShell.webView.isLoading ) {
DispatchQueue.main.async(execute: {
PWAShell.webView.evaluateJavaScript("this.dispatchEvent(new CustomEvent('push-notification', { detail: \(json) }))")
})
}
else {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
checkViewAndEvaluate()
}
}
}
checkViewAndEvaluate()
checkViewAndEvaluate(event: "push-notification", detail: json)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ let displayMode = "standalone" // standalone / fullscreen.
let adaptiveUIStyle = true // iOS 15+ only. Change app theme on the fly to dark/light related to WebView background color.
let overrideStatusBar = false // iOS 13-14 only. if you don't support dark/light system theme.
let statusBarTheme = "dark" // dark / light, related to override option.
let pullToRefresh = true // Enable/disable pull down to refresh page
Loading

0 comments on commit 19d2ec8

Please sign in to comment.