Skip to main content

97 posts tagged with "iOS"

View All Tags

Adding Charts to SwiftUI: A Practical Guide

Published: · Last updated: · 7 min read
Sandra Rosa Antony
Software Engineer, Appxiom

Charts play a key role when it comes to turning raw data into something people can actually understand. Whether you're tracking user activity, visualizing growth, or summarizing analytics, charts help communicate complex information quickly and clearly.

SwiftUI already gives you a powerful way to build clean, modern interfaces. And with Apple's Charts library, bringing interactive and visually rich charts into your iOS apps feels like a natural extension of the SwiftUI workflow - not an extra chore.

In this guide, we'll walk through how to integrate charts into SwiftUI applications, build different chart types like bar charts, line charts, and pie-style charts, and tweak their appearance so they fit seamlessly into your app's design. The goal is simple: help you move from data to insight with minimal effort and maximum clarity.

Let's start building.

Importing the Charts Library

Apple introduced the Charts framework starting from iOS 16. It's built specifically for SwiftUI, so it fits naturally into the declarative UI flow you're already using.

First, make sure your project meets these requirements:

  • iOS 16 or later
  • SwiftUI-based app
  • Xcode 14+

Then, simply import Charts wherever you plan to use it:

import Charts

That's it. No external dependencies, no package managers, no setup headaches.

Creating a Simple Bar Chart

Let's start with something simple and practical - a bar chart. Bar charts are usually the first choice when you want to compare values across categories, like monthly sales, usage stats, or feature adoption.

Suppose you want to show how sales performed over the first few months of the year. With SwiftUI and the Charts library, you can set this up with very little code:

struct BarChartView: View {
var body: some View {
Chart {
BarMark(
x: .value("X", 1),
y: .value("Y", 10)
)

BarMark(
x: .value("X", 2),
y: .value("Y", 20)
)

BarMark(
x: .value("X", 3),
y: .value("Y", 30)
)

BarMark(
x: .value("X", 4),
y: .value("Y", 40)
)

BarMark(
x: .value("X", 5),
y: .value("Y", 50)
)

BarMark(
x: .value("X", 6),
y: .value("Y", 60)
)
}
.frame(height: 300)
.padding()
}
}

Here's what's happening under the hood:

  • Chart acts as the container that holds and renders your chart.
  • BarMark tells SwiftUI that you want to display the data as vertical bars.
  • Each tuple in the data array represents a single bar:
    • The first value maps to the x-axis (for example, months).
    • The second value maps to the y-axis (such as sales numbers).

SwiftUI automatically handles layout, scaling, and axis rendering for you. You don't need to manually calculate positions or sizes - the chart adapts based on the data you provide. This makes bar charts a great starting point when you want quick, readable visualizations without a lot of setup.

Once you're comfortable with this pattern, you can easily extend it to real-world data coming from APIs, databases, or user input.

Creating Other Types of Charts

Once you understand one chart type, the rest feel familiar. You mostly change the mark.

Perfect for showing progress over time.

var body: some View {
Chart(data) { item in
LineMark(
x: .value("Day", item.day),
y: .value("Value", item.value)
)
.foregroundStyle(.blue)
.lineStyle(StrokeStyle(lineWidth: 3))

PointMark( // optional: show dots on points
x: .value("Day", item.day),
y: .value("Value", item.value)
)
.foregroundStyle(.blue)
}
.frame(height: 300)
.padding()
}

Line charts are ideal for things like:

  • Growth metrics
  • Performance tracking
  • Time-based analytics

Pie Chart (Proportions and Distribution)

let data: [Country] = [
Country(name: "India", population: 1428),
Country(name: "China", population: 1412),
Country(name: "USA", population: 339),
Country(name: "Indonesia", population: 277),
Country(name: "Pakistan", population: 240),
Country(name: "Brazil", population: 216)
]
var body: some View {
Chart(data) { item in
SectorMark(
angle: .value("Population", item.population)
)
.foregroundStyle(by: .value("Country", item.name))
}
.frame(height: 350)
.padding()
}

Use pie charts sparingly. They're best when comparing parts of a whole, not precise values.

Scatter Plot (Finding Patterns)

Scatter plots are useful when comparing two continuous variables.

var body: some View {
Chart(sampleData) { dataPoint in
PointMark(
x: .value("Hours Used", dataPoint.dailyHours),
y: .value("Social Battery %", dataPoint.socialBattery)
)
}
.frame(height: 300) // Set a frame height for better display
.padding()
}

These are great for:

  • Identifying outliers
  • Spotting correlations
  • Visualizing raw data points

You can choose the chart type that best suits your data visualization needs.

Customizing the Look and Feel of Your Charts

Once your chart is working, the next question is always the same: "How do I make this match my app's design?"

That's where customization comes in.

SwiftUI's Charts library gives you a lot of control over how your charts look - colors, text styles, and overall presentation - without turning your code into a mess.

Here's a simple example of customizing a bar chart:

var body: some View {
Chart(data, id: \.x) { item in
BarMark(
x: .value("X Value", item.x),
y: .value("Y Value", item.y)
)
.foregroundStyle(Color.red) // Fill color
.clipShape(RoundedRectangle(cornerRadius: 4))
.annotation(position: .overlay) { // Stroke workaround
Rectangle()
.stroke(Color.black, lineWidth: 1)
}
}
.chartXAxis {
AxisMarks { _ in
AxisValueLabel()
.font(.system(size: 12)) // Axis label font
}
}
.chartYAxis {
AxisMarks { _ in
AxisValueLabel()
.font(.system(size: 12))
}
}
.frame(height: 300)
.padding()
}

What this customization does:

  • Bar color: Each bar is styled with a red fill using foregroundStyle(Color.red). This helps the data stand out instantly and keeps the chart visually focused on the values.

  • Rounded bar edges: The clipShape(RoundedRectangle(cornerRadius: 4)) adds subtle rounded corners to the bars. It's a small touch, but it makes the chart look cleaner and more modern.

  • Bar outlines for clarity: Since Charts doesn't provide a direct stroke modifier for bars, an overlay annotation is used to draw a black border around each bar. This improves visual separation, especially when bars are close in value.

  • X-axis labels: The X-axis is customized using chartXAxis with AxisMarks. The label font is set to a smaller system font, keeping it readable without overwhelming the chart.

  • Y-axis labels: The Y-axis follows the same approach as the X-axis, maintaining visual consistency and ensuring values are easy to scan at a glance.

  • Layout and spacing: The chart is given a fixed height of 300 points and padded on all sides. This prevents crowding and ensures the chart fits comfortably within the UI.

These small tweaks go a long way. They help your charts feel like a natural part of your app instead of something that looks bolted on. Whether you're matching a brand color palette or improving readability, SwiftUI makes it easy to fine-tune charts without overcomplicating your layout.

Once you're comfortable with these basics, you can layer in more advanced styling to create charts that are both functional and visually polished.

Conclusion

We've walked through how charts fit into SwiftUI apps using the Charts library—from setting things up to building bar charts, line charts, pie charts, and scatter plots, and finally shaping them to match your app's design. Each chart type serves a purpose, and when used thoughtfully, they turn raw numbers into something users can actually understand.

The best approach is to start small. Add a simple bar chart. Make sure it's clear and readable. Then, as your app grows, experiment with lines, points, and sectors where they make sense. Charts should guide users, not overwhelm them—clarity always matters more than visual flair.

When done right, charts don't just display data. They help users see patterns, understand trends, and make confident decisions. And that's where good design and good data meet.

Happy coding.

Concurrency and Parallelism in Swift: How iOS Apps Stay Fast and Responsive

Published: · Last updated: · 5 min read
Sandra Rosa Antony
Software Engineer, Appxiom

You've probably felt it before.

You tap a button. Nothing happens.

You scroll a list. It stutters.

You wonder if the app is frozen - or just thinking too hard.

Most of the time, this isn't because the app is doing too much. It's because it's doing the right work in the wrong place.

Modern iOS apps are expected to stay smooth no matter how much work is happening behind the scenes. Network calls, image processing, database operations - all of this needs to run without blocking the UI.

That's where concurrency and parallelism come in. When used correctly, they let your app work hard in the background while the UI stays smooth and responsive. When used poorly, they lead to hangs, race conditions, and subtle performance issues that users feel long before you see a crash report.

Let's break this down - clearly and practically.

Concurrency vs Parallelism - Clear and Simple

Before jumping into code, let's clear up the big question:

Concurrency means handling multiple tasks at the same time conceptually - tasks start, run, and complete in overlapping time periods.

Parallelism means executing multiple tasks literally at the same time, usually on multiple CPU cores.

Think of concurrency as juggling multiple balls, while parallelism is having multiple people toss those balls simultaneously.

In Swift, both concepts help make apps feel fast and responsive, but they solve slightly different problems.

Achieving Concurrency in Swift

Concurrency is about managing multiple tasks at once, even if they aren't running at the same exact moment. Swift gives us multiple tools to achieve this, each suited for different scenarios.

1. Grand Central Dispatch (GCD)

GCD is the foundation of swift multithreading. It allows you to move work off the main thread so your UI doesn't block.

let queue = DispatchQueue(label: "com.example.myqueue")
queue.async {
// perform task asynchronously
}

GCD works well when:

  • You need quick background execution
  • You want control over priority (QoS)
  • You're performing independent tasks like parsing, disk I/O, or network calls

However, GCD relies heavily on callbacks. As projects grow, nested closures can become difficult to read and maintain.

2. Async / Await (Swift Concurrency)

Swift's modern concurrency model changed how developers think about async code.

Instead of managing queues and callbacks, you write code that reads almost like synchronous logic:

func fetchData() async throws -> Data {
let url = URL(string: "https://example.com/data.json")!
let (data, _) = try await URLSession.shared.data(from: url)
return data
}

do {
let data = try await fetchData()
// handle data
} catch {
// handle error
}

This makes concurrent flows easier to reason about and significantly reduces mistakes.

Async/await is ideal when:

  • Performing network requests
  • Coordinating dependent async tasks
  • Writing readable, structured concurrency code

Swift Concurrency doesn't replace GCD entirely - but for most app-level use cases, it's now the preferred approach.

3. Operation and OperationQueue

Operation and OperationQueue sit at a higher abstraction level than GCD.

They shine when:

  • Tasks depend on each other
  • You need cancellation support
  • You want fine-grained control over execution order
class MyOperation: Operation {
override func main() {
// perform task
}
}

let queue = OperationQueue()
let op1 = MyOperation()
let op2 = MyOperation()
let op3 = MyOperation()
op2.addDependency(op1)
op3.addDependency(op2)
queue.addOperations([op1, op2, op3], waitUntilFinished: false)

Operations can be paused, cancelled, prioritized, and chained - making them perfect for complex workflows like file uploads, background syncing, or batch processing.

If GCD is a power tool, OperationQueue is a workflow manager.

Achieving Parallelism in Swift

Parallelism is about doing multiple things at the same time, usually across different CPU cores. This is where performance gains can be dramatic - but also risky if misused.

1. Threading

At the lowest level, Swift supports manual thread management.

let thread = Thread {
// perform task in separate thread
}
thread.start()

Direct threading is rarely recommended today. It's easy to misuse and hard to scale safely. Most modern Swift apps rely on higher-level abstractions like GCD or Swift Concurrency instead.

Still, understanding threads helps you understand why parallelism behaves the way it does.

2. DispatchQueue.concurrentPerform

When you need true parallel execution, DispatchQueue.concurrentPerform is one of the most powerful tools available.

let count = 1000000
var results = [Int](repeating: 0, count: count)
DispatchQueue.concurrentPerform(iterations: count) { index in
results[index] = index * 2
}

This method:

  • Splits work across available CPU cores
  • Executes iterations in parallel
  • Blocks until all tasks complete

It's ideal for CPU-intensive tasks like:

  • Image processing
  • Data transformation
  • Batch calculations

Important: Never run concurrentPerform on the main thread. Doing so will block the UI and negate all benefits of parallelism.

Used correctly, concurrentPerform is one of the most efficient ways to handle parallel workloads in multithreading Swift apps.

Choosing the Right Tool (This Matters)

Not every concurrency problem needs the same solution.

  • Use Swift Concurrency for async workflows and networking
  • Use GCD for low-level control and background tasks
  • Use concurrentPerform for parallel CPU-bound work

Real-world apps often mix all three. That's normal. The goal isn't purity - it's performance without surprises.

Why Multithreading Swift Apps Still Goes Wrong

Most performance issues don't come from doing too much work.

They come from doing the right work in the wrong place.

Common mistakes include:

  • Blocking the main thread
  • Running parallel work where concurrency would suffice
  • Overusing background threads without coordination

This is where monitoring becomes just as important as implementation.

Final Thoughts

Concurrency isn't about making your app complicated.

It's about making it feel effortless.

When multithreading Swift is done right, users never notice it.

They just notice that your app feels fast, smooth, and reliable.

Understanding data structures and algorithms in Swift is important - but understanding multithreading Swift, concurrency models, and parallel execution is what keeps your app fast, responsive, and trustworthy.

Because great apps aren't just built - they're engineered to stay responsive under pressure.

How SwiftyGif Simplifies GIF Handling in iOS Apps

Published: · Last updated: · 5 min read
Robin Alex Panicker
Cofounder and CPO, Appxiom

When you build SDKs or apps long enough, you start noticing patterns.

One of them is this: developers love adding motion to their apps - until motion starts fighting back.

GIFs are a perfect example.

On paper, they're simple. Drop in a file, play it, done.

In reality? Native iOS support is… let's say minimal. You end up decoding frames manually, managing timing, watching memory spike, and wondering why something so small turned into a whole sprint.

I've seen teams delay releases just because a loading GIF caused stutters on older devices. And I've also seen apps feel instantly more polished once GIFs were handled properly.

That's where SwiftyGif quietly does its job - and does it well.

Let's talk about why it exists, how it fits into real products, and how to use it without turning your codebase into a science experiment.

Why GIF Handling Is Hard in iOS

iOS technically supports animated images, but real-world apps expose the cracks quickly. Large GIFs consume memory fast. Multiple GIFs on a screen can slow down scrolling. Older devices struggle even more.

Most teams don't notice these issues during development. They show up later - as UI lag, dropped frames, or subtle performance regressions.

SwiftyGif exists to take care of these problems so you don't have to reinvent GIF playback logic yourself.

Integrating SwiftyGif

Getting started with SwiftyGif is straightforward. You can add it to your project using whichever dependency manager you already use - CocoaPods, Carthage, or Swift Package Manager.

CocoaPods:

pod 'SwiftyGif'

Carthage:

github "SwiftyGif/SwiftyGif"

Swift Package Manager: Add the package with the URL https://github.com/alexiscreuzot/SwiftyGif for compatibility with Swift Package Manager.

There's no special setup, no configuration files, and no extra steps after installation. Once the dependency is added, you're ready to start displaying GIFs.

This simplicity is intentional. SwiftyGif is designed to fit into existing projects without friction.

Displaying a GIF in Your App

SwiftyGif introduces a custom image view called SwiftyGifView. Think of it as a smarter UIImageView - built specifically for GIF playback.

let gifImageView = SwiftyGifView()
gifImageView.setGifImage(gif)

Advantages of Using SwiftyGif

Controlling GIF Playback

Once a GIF is loaded, SwiftyGif gives you control when you need it.

You can pause and resume animations, adjust playback speed, control looping behavior, and even respond to user interactions like taps. This is useful when GIFs are part of user flows, not just decorative elements.

The following code snippet illustrates this control:

let gifManager = SwiftyGifManager(memoryLimit: 20)
let gifImageView = SwiftyGifView()
gifImageView.setGifImage(gif, manager: gifManager)
gifImageView.speed = 2.0

For example, slowing down a GIF during onboarding or stopping animations when a screen goes off-screen helps keep the experience intentional and efficient.

Keeping Animations Smooth

One of SwiftyGif's biggest strengths is performance. The library is optimized to keep animations smooth without overloading the CPU.

Even with larger GIFs, playback stays stable. Scrolling doesn't stutter. UI responsiveness remains intact.

This matters more than it sounds. Animations that feel "almost smooth" are often worse than no animation at all. SwiftyGif focuses on avoiding that middle ground.

Managing Memory with SwiftyGifManager

GIFs can consume a lot of memory, especially when multiple animations are active at the same time. SwiftyGif addresses this with SwiftyGifManager.

The manager lets you define memory limits for GIF playback. Once those limits are reached, SwiftyGif handles things gracefully instead of letting memory usage spiral out of control.

This is especially helpful in apps with feeds, dashboards, or onboarding flows that use more than one GIF at a time.

let gifManager = SwiftyGifManager(memoryLimit: 20)
let gifImageView = SwiftyGifView()
gifImageView.setGifImage(gif, manager: gifManager)

Loading GIFs from a URL

SwiftyGif also supports loading GIFs directly from remote URLs. This is useful for apps that display dynamic or server-driven content.

You point the GIF view to a URL, and SwiftyGif takes care of loading and playback. No custom decoding logic needed.

As always, remote content should be handled thoughtfully—but SwiftyGif makes the technical side simple.

let remoteGifURL = URL(string: "https://example.com/your_gif.gif") 
let gifImageView = SwiftyGifView()
gifImageView.setGifFromURL(remoteGifURL)

Common Pitfalls to Avoid

Even with the right library, a few mistakes can still sneak in:

  • Overusing large GIFs where lightweight animations would work
  • Forgetting to manage memory when multiple GIFs are active
  • Treating decorative animations as free from performance cost

SwiftyGif helps, but thoughtful usage matters just as much.

Final Thoughts

SwiftyGif doesn't try to be flashy. It doesn't promise magic.

It does something better: it solves a very specific problem - GIF handling on iOS - and does it reliably, efficiently, and with respect for your codebase.

If your app uses GIFs in any meaningful way, SwiftyGif gives you control without complexity. And when paired with proper performance visibility, it helps ensure those animations stay delightful instead of becoming liabilities.

Sometimes, the best libraries are the ones you don't think about after integration. SwiftyGif fits that description perfectly.

Data Structures in Swift: A Practical Guide for iOS Developers

Published: · Last updated: · 6 min read
Don Peter
Cofounder and CTO, Appxiom

Every Swift developer eventually runs into the same moment.

The app works fine… until it doesn't.

Scrolling becomes sluggish. Memory usage slowly creeps up. A feature that worked perfectly in testing starts behaving strangely in production. And when you dig deep enough, the issue often traces back to one thing: how data is stored and managed.

That's where swift data structures come in.

This blog is a practical walkthrough of data structures in Swift, not from a textbook point of view, but from how they actually show up in real iOS apps. If you've ever wondered how DSA in Swift connects to everyday development, this guide is for you.

A Practical Checklist for Writing iOS Framework Documentation Developers Will Actually Use

Published: · Last updated: · 7 min read
Andrea Sunny
Marketing Associate, Appxiom

If you've ever integrated a third-party iOS framework, you already know this truth: great code means nothing if the documentation is confusing.

An iOS framework exists to make another developer's life easier. But without clear documentation, even the most powerful framework feels hard to adopt, risky to use, and easy to abandon. Documentation isn't an afterthought - it's the bridge between your framework and its users.

Think of your documentation as a guided walkthrough. When done right, it answers questions before they're asked and removes friction at every step. Let's walk through how to build documentation that developers trust, understand, and keep coming back to.

Top 10 App Store Submission Tips for iOS Developers and Product Owners

Published: · Last updated: · 12 min read
Andrea Sunny
Marketing Associate, Appxiom

Imagine this: You've spent months building your iOS app. You've tested it, fine-tuned every detail, and you're finally ready to show it to the world. You hit "Submit to App Store"... and then the anxiety kicks in. Did you miss anything? Will it get rejected? Did you choose the right account type?

Deploying an iOS app isn't just about shipping code. It's about understanding Apple's ecosystem, speaking their language, and following their rules - without losing your mind.

I've been through the launch chaos, the unexpected rejections, and the "why didn't anyone tell me this?" moments. So here's your shortcut: the 10 things I wish I knew before hitting that submit button.

App Hangs in iOS: Causes, Code Fixes, and How to Spot Them

Published: · Last updated: · 5 min read
Don Peter
Cofounder and CTO, Appxiom

Ever tapped a button in your app and waited... and waited... until you started questioning your life choices?

Yeah, that's an app hang.

It's not a crash. It's worse. Your app doesn't explode, it just freezes. Quietly. Awkwardly. Like someone forgot their lines on stage and now the whole audience is staring.

App hangs are sneaky. They don't always show up in crash reports. But your users feel them. In the lags, the unresponsive screens, the moments when they swipe but nothing moves. And if it happens too often? That uninstall button starts looking real attractive.

But it doesn't have to be that way.

Let's fix the freeze before the curtain falls.

Smarter iOS App Testing with BrowserStack and Appxiom

Published: · Last updated: · 6 min read
Andrea Sunny
Marketing Associate, Appxiom

You're test-driving a car. Everything seems fine, until you hit 60 mph and the steering wheel starts shaking. Weird, right? You take it back to the shop, only to hear, "Oh, that only happens on highways. We didn't test for that."

Now imagine that same moment, but with your iOS app. It passes all your tests locally. Looks great on your simulator. But when it lands in the real world? Crash on iOS 16.3. A layout glitch on the iPhone SE. A memory spike on iPadOS.

Here comes your first comment, "App keeps crashing when I switch tabs. iOS 16.3."

And boom! Your 5-star rating dips, users uninstall, and your team scrambles in damage-control mode.

That's why modern iOS teams don't just test. They test right.

Let's talk about Appxiom + BrowserStack - a killer combo that brings you deep device coverage and smart issue detection in one efficient workflow.

What is BrowserStack?

BrowserStack is your all-access pass to testing iOS apps on real devices, without needing to build your own hardware lab. From the latest iPhones to older iPads running quirky iOS versions, it gives you cloud-based access to actual devices (not emulators), so you can run both manual and automated tests with ease. Think of it as having a fully-stocked Apple device warehouse right in your browser. Whether you're running regression tests or checking cross-device compatibility, BrowserStack helps you ensure your app looks sharp and works flawlessly, no matter where or how your users open it.

What Is Appxiom?

Now here's where Appxiom steps in, and turns up the heat in the best way possible.

Appxiom is a real-time issue detection platform that helps you catch crashes, performance drops, and user-impacting bugs during testing, before your users ever see them.

If BrowserStack shows you where your app might stumble, Appxiom shows you why. While your tests run across real iOS devices, Appxiom is silently at work in the background, listening in on everything that happens beneath the surface.

Crashes during navigation? It catches them. Memory leaks hiding behind a clean UI? Detected. Janky scrolls, sluggish taps, or performance drops? Marked. Bugs that quietly kill conversions? Flagged with business impact.

Appxiom doesn't just collect this data, it translates it into rich, actionable insights. You get real-time issue reports that include severity, device context, and user flow impact, all wrapped in a developer-friendly dashboard. Instead of digging through logs or guessing what went wrong, you know exactly what to fix, and why it matters.

The result? You stop reacting to bug reports after users complain and start resolving issues before they ever hit production. With Appxiom riding alongside your BrowserStack tests, every test session becomes a proactive debugging session. It's like running your app through an MRI while it performs on stage—and getting the results instantly.

How to Integrate BrowserStack and Appxiom Together for Smarter iOS Testing

Here's how to integrate BrowserStack and Appxiom into your iOS workflow:

Step 1: Setting Up BrowserStack

Head to browserstack.com and create your account. Explore their documentation to understand device setup, automation tools, and test configuration. Install required SDKs and dependencies for running your iOS tests.

Step 2: Integrating Appxiom

Register with Appxiom at appxiom.com and log in to the dashboard. Click "Add App" to connect your iOS app. Follow integration steps in the Appxiom Docs to embed the Appxiom framework into your app. Run a quick sanity test to make sure the integration is successful.

Step 3: Running Tests on BrowserStack

Choose your target iPhones or iPads from BrowserStack's real device lab. Configure the test environment and load your Appxiom-integrated app. Use your test framework to run automated test cases. Monitor UI behavior, response times, and user flow - all in real-time.

Step 4: Analyzing Appxiom Reports

Log in to your Appxiom dashboard after running tests on BrowserStack. Identify performance issues, crashes, UI glitches, or slowdowns detected during testing. Review detailed bug reports with data points like issue type, severity, device info, and timestamps. Use these insights to reproduce and resolve bugs quickly.

The Power of Pairing: Why BrowserStack + Appxiom Just Makes Sense

Imagine this: You're testing your iOS app on a real iPhone 14 using BrowserStack. Everything looks smooth on the surface. But beneath that pixel-perfect UI, Appxiom is quietly watching for deeper issues - things no visual test would catch.

That's the beauty of using both tools together. One handles the "outside," the other handles the "inside." And when paired, they give you something every developer dreams of: complete visibility.

Here's what you really get when you bring them together:

1. Enhanced Device Coverage

With BrowserStack, you're testing on actual iOS hardware. No flaky emulators, no simulator - only bugs. You see what your users see.

2. Silent Bug Surveillance

Silent killers like API issues, memory spikes, UI jank usually go undetected until it's too late. Appxiom flags them in real time, even if no one reports them.

3. Crystal-Clear Reproduction

When a bug appears, Appxiom shows you where, how, and why it happened, right down to the device, OS version, and line of code. Combine that with BrowserStack's stable testing environment, and reproducing bugs becomes effortless.

4. Fix What Matters, Fast

Not all bugs deserve a panic patch. Appxiom tells you which ones are impacting your users the most, so you prioritize smart, not out of fear.

5. Save Time. Save Budget. Save Face.

No more post-release chaos. With better pre-release coverage and proactive detection, you catch problems early, and avoid costly fixes later.

In Summary

Testing on real devices? Necessary. Catching hidden bugs before users do? Priceless.

With BrowserStack, you test how your app looks and behaves. With Appxiom, you understand how it performs and fails, even when it looks fine.

Together? You've got a world-class iOS testing workflow that keeps your app sharp, your users happy, and your team confident.

Start using Appxiom with BrowserStack today!

Because flawless apps aren't built by chance. They're built by choice.

WHATS NEW IN STORE FOR DEVELOPERS WITH SWIFT 6.

Published: · Last updated: · 6 min read
Don Peter
Cofounder and CTO, Appxiom

Swift 6 introduces new and creative functionalities aimed at improving your coding experience and enabling you to develop more sturdy and effective applications.

Exploring the key features of Swift 6, from advancements in concurrency to fine-tuning functions, this blog post uncovers the top 4 highlights. Discover how these enhancements can enhance your development process and open up new opportunities for your projects.

1. Swift Concurrency Isolation

Swift Concurrency is designed to ensure data safety by implementing a system that isolates code execution with actors. Actors in Swift are a concurrency feature introduced in Swift 5.5. They are designed to protect their state from data races and ensure that only one piece of code can access an actor's data at a time.

By confining code execution within these isolated units, Swift Concurrency minimizes the risk of conflicts arising from simultaneous access to shared data. In order to send data between these units, developers has to use Sendable types. You can read in detail about sendable types here https://developer.apple.com/documentation/swift/sendable

However, while this mechanism enhances data safety, it also introduces certain constraints on programming practices. Specifically, some commonly used patterns involve non-Sendable data, like classes or mutable structs, which refers to data that is not inherently safe to share across different contexts. This is because using non-Sendable types concurrently can lead to data races and compiler warns developers against it.

This limitation can impact how developers write their programs, as they must carefully consider the implications of sharing non-Sendable data within the context of Swift Concurrency.

// Not Sendable
class Client {
init(name: String, initialBalance: Double) { ... }
}

actor ClientStore {
var clients: [Client] = []

static let shared = ClientStore()

func addClient(_ c: Client) {
clients.append(c)
}
}

func openNewAccount(name: String, initialBalance: Double) async {
let client = Client(name: name, initialBalance: initialBalance)
await ClientStore.shared.addClient(client) // Error! 'Client' is non-`Sendable`!
}

1.1 Introducing Isolation Regions

Swift 6 introduces a new feature known as isolation regions, which revolutionizes the way the compiler comprehends data usage and ensures security during the transmission of non-Sendable values across isolation boundaries like actors. Isolation regions essentially equip the compiler with the ability to analyze how data is utilized, thereby enabling it to ascertain whether two data entities have the potential to influence each other and cause data race situations.

There is nothing specific for the developer to do for this capability to be activated, except upgrading to Swift 6.

2. Count and Filter

Swift now includes a nifty feature called count(where:). This method lets you efficiently count elements in a collection that meet a specific condition. It combines the functionality of filter() (which creates a new array with matching elements) and count() (which calculates the number of elements) into a single step.

let testScores = [70, 85, 90, 68, 95]
let passingCount = testScores.count(where: { $0 >= 85 })

print("Number of tests with scores 85 or higher:", passingCount)

This not only saves you from creating unnecessary temporary arrays, but also provides a cleaner and more readable way to achieve this common task.

The beauty of count(where:) is that it's not limited to just arrays. It works with any collection type that conforms to the Sequence protocol, including sets and dictionaries. This gives you a powerful and versatile tool for working with various data structures in Swift.

3. Error Handling with Typed Throws

Swift introduces a much-awaited feature: "typed throws." This eliminates a common frustration with error handling - the need for a general catch clause even when you've caught all specific errors.

enum RegistrationError: Error {
case notAlphaNumbericChars
}
  • Specificity: You can now declare precisely what types of errors a function can throw using throws(OneSpecificErrorType). This signals that only that specific error type can be thrown by the function.

  • Cleaner Code: Since Swift knows the exact error type, you can write more concise code. For example, if your function throws only RegistrationError, you can write throw .notAlphaNumbericChars instead of a generic error message.

do {
register()
} catch RegistrationError.notAlphaNumbericChars {
print("Please make sure password filed contains alpha numberic Characters")
}
  • Automatic Type Inference: In a do block that throws only one type of error, the error value in a general catch block automatically becomes the specific error type instead of a generic Error.

  • Improved Safety: Swift throws a compile-time error if you attempt to throw an error not listed in the throws clause.

  • Expressive Rethrows: You can write rethrows more clearly in many cases. For example, throws(any Error) is equivalent to just throws, and throws(Never) signifies a non-throwing function.

4. Internal Imports within Modules

Imagine a large e-commerce application with a modular architecture:

  • Core Functionality: This core module handles essential functionalities like product management, shopping cart handling, and user authentication.

  • Payment Processing: This separate module deals with secure payment processing and integrates with various payment gateways.

  • Analytics & Logging: This module is responsible for tracking user interactions, logging events, and potentially utilizing third-party analytics services.

4.1 Challenge: Dependency Management

The core application depends on both Payment Processing and Analytics & Logging modules. However, ideally, the core functionality shouldn't expose these internal dependencies to other parts of the codebase.

internal import <ModuleName>

4.2 Access Control Modifiers to the Rescue

Swift 6.0's access control modifiers on import statements come in handy here:

  • Private Imports: The core module can privately import the Payment Processing and Analytics & Logging modules. This ensures that these dependencies are not accidentally exposed or used outside the core module.

  • Encapsulation and Security: By keeping payment processing and analytics private, the core module promotes better encapsulation and potentially strengthens security by limiting access to sensitive functionalities.

These are the top 4 new features in Swift 6.0, in my opinion.

Happy Coding and Bug Fixing.

UPDATES FOR IOS DEVELOPERS IN THE EU: INTRODUCING WEB DISTRIBUTION

Published: · Last updated: · 4 min read
Don Peter
Cofounder and CTO, Appxiom

Apple is bringing more options for distributing your apps in the EU due to Digital Markets Act (DMA). Whether you’re a seasoned developer or just starting out, these changes are positioned as a way to reach more users and enhance your app distribution strategies.

Developers have the option to stick with the existing App Store business terms or opt for the new terms tailored for iOS apps in the EU. Under the new EU business terms, developers can decide to distribute iOS apps within the EU through the App Store, other alternative app marketplaces or through own hosting.

Alternative distribution channels

Following are the two additional methods for developers to distribute iOS apps in EU along with App store distribution,

  • Third party App Marketplaces: Now, third party marketplaces have the option to offer a catalog of apps. This opens up new avenues for app discovery and distribution.

  • Linking out to Purchase: Developers can now choose how to design promotions, discounts, and other deals when directing users to complete a transaction for digital goods or services on an external webpage. The Apple-provided design templates are now optional, giving you more control over your promotional strategies.

Introducing Web Distribution for iOS

One of the most exciting updates is the introduction of Web Distribution, which allows authorized developers to distribute their iOS apps directly from their own website. Here’s what you need to know,

  • With Web Distribution, you can distribute your iOS apps to EU users directly from your website, giving you more control over the distribution process.

  • Apple will provide access to APIs that facilitate app distribution from the web, integrate with system functionality, back up and restore users’ apps.

  • Apps offered through Web Distribution must meet Notarization requirements just like in macOS apps to protect platform integrity, ensuring a secure experience for users. You can read more on notarization requirements here https://developer.apple.com/documentation/security/notarizing_macos_software_before_distribution

Eligibility and Requirements

To be eligible for Web Distribution, developers must meet specific criteria and commit to ongoing requirements to protect users. Here’s what you need to know,

  • Developers must be enrolled in the Apple Developer Program as an organization incorporated, domiciled, and/or registered in the EU.

  • Must be a member of Good Standing in the Apple Developer Program for Two Continuous Years or More,

This means that developers need to maintain their membership in the Apple Developer Program for at least two consecutive years without any significant issues or violations.

  • It ensures that developers have been actively engaged with the program and have adhered to its terms and conditions for a substantial period.

  • App with More Than One Million First Annual Installs on iOS in the EU in the Prior Calendar Year,

This refers to the number of initial installations (installs) of an app on iOS devices in the European Union during a single year. The app must have achieved more than one million first annual installs specifically within the EU region during the previous calendar year.

  • The requirement doesn't state that the app must consistently maintain one million installs each year to remain in the program.

  • Developers must agree to various terms, including offering apps only from their developer account, being responsive to communications from Apple, publishing transparent data collection policies, and following applicable laws.

Payments, Fees, and Taxes

We want to ensure that developers have clarity on payments, fees, and taxes associated with Web Distribution. Here’s what you need to know,

  • A Core Technology Fee (CTF) will be charged by apple.

What is the Core Technology Fee (CTF)?

It's a fee that developers pay to Apple.

  • It shows appreciation for the tools and support Apple offers to developers.

  • How is it calculated?

Developers pay €0.50 for first annual installs over one million in the past 12 months.

If a user has installed the app in multiple devices it will be treated as a single install only.

  • If your app has more than one million installs in a year, you pay this fee for each additional install beyond that.

  • Why does Apple charge this fee?

It helps Apple to cover the costs of maintaining and improving the tools and services that developers use.

  • It supports ongoing investments in technology to benefit developers and users alike.

  • Nonprofit organizations, accredited educational institutions, or government entities based in the EU that have been approved for a fee waiver are exempt from the Apple Developer Program annual membership fee and the Core Technology Fee.

  • Developers are responsible for collecting, reporting, and remitting any required tax to the appropriate tax authorities for transactions that take place using Web Distribution.

INTEGRATING URL_LAUNCHER IN FLUTTER APPS

Published: · Last updated: · 4 min read
Don Peter
Cofounder and CTO, Appxiom

The mobile app development world has moved from fast to ‘impatiently fast’. One essential aspect of faster user interaction is the ability to navigate to external websites or open other apps directly from within your Flutter application.

This is where the url_launcher plugin for Flutter comes into play. This plugin allows you to open URLs in the default web browser of the device. It also allows for ​​opening URLs that launch other apps installed on the device such as emails or social media apps. 

Installing URL Launcher in Flutter

Installation can be done in a whiff by following the code given below: 

Terminal Command

flutter pub add url_launcher

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

dependencies:
url_launcher: x.y.z.

Supported URL Schemes

url_launcher supports various URL schemes. They are essentially prefixes or protocols that help define how a URL should be handled by Android, iOS or any operating system or apps in general. Common URL Schemes supported by url_launcher include HTTP, HTTPS, mailto, SMS, tel, App Schemes and Custom Schemes. 

Integrating url_launcher

When using the url_launcher package, you can open URLs with these schemes using the launch function. This package will delegate the URL handling to the underlying platform, ensuring compatibility with both Android and iOS. 

import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

class MyApp extends StatelessWidget {

@override Widget build(BuildContext context) {

    return MaterialApp(

      home: Scaffold(

        appBar: AppBar(
          title: Text('URL Launcher Example'),
        ),

        body: Center(
          child: ElevatedButton(

            onPressed: () {
              _openURL("https://appxiom.com/");
            },

            child: Text('Open URL'),

          ),

        ),

      ),

    );

  }

  // Function to open a URL using url_launcher

  void _openURL(String url) async {

    if (await canLaunchUrl(url)) { //Checking if there is any app installed in the device to handle the url.

      await launch(url);

    } else {

      // Handle error

    }

  }

}

Configuring canLaunchUrl in iOS

Make sure to add the URL schemes passed to canLaunchUrl as LSApplicationQueriesSchemes entries in your info.plist file. Otherwise, it will return false.

<key>LSApplicationQueriesSchemes</key>

<array>

  <string>sms</string>

  <string>tel</string>

</array>

Configuring canLaunchUrl in Android

Add the URL schemes passed to canLaunchUrl as <queries> entries in your AndroidManifest.xml, otherwise, it will return false in most cases starting on Android 11 (API 30) or higher. 

&lt;!-- Provide required visibility configuration for API level 30 and above --&gt;

&lt;queries&gt;

&nbsp;&nbsp;&lt;!-- If your app checks for SMS support --&gt;

&nbsp;&nbsp;&lt;intent&gt;

&nbsp;&nbsp;&nbsp;&nbsp;&lt;action android:name="android.intent.action.VIEW" /&gt;

&nbsp;&nbsp;&nbsp;&nbsp;&lt;data android:scheme="sms" /&gt;

&nbsp;&nbsp;&lt;/intent&gt;

&nbsp;&nbsp;&lt;!-- If your app checks for call support --&gt;

&nbsp;&nbsp;&lt;intent&gt;

&nbsp;&nbsp;&nbsp;&nbsp;&lt;action android:name="android.intent.action.VIEW" /&gt;

&nbsp;&nbsp;&nbsp;&nbsp;&lt;data android:scheme="tel" /&gt;

&nbsp;&nbsp;&lt;/intent&gt;

&nbsp;&nbsp;&lt;!-- If your application checks for inAppBrowserView launch mode support --&gt;

&nbsp;&nbsp;&lt;intent&gt;

&nbsp;&nbsp;&nbsp;&nbsp;&lt;action android:name="android.support.customtabs.action.CustomTabsService" /&gt;

&nbsp;&nbsp;&lt;/intent&gt;

&lt;/queries&gt;

That’s it for now. For more information on  url_launcher with Flutter, check https://pub.dev/packages/url_launcher/

A CHECKLIST FOR CREATING DOCUMENTATION FOR AN IOS FRAMEWORK

Published: · Last updated: · 9 min read
Don Peter
Cofounder and CTO, Appxiom

iOS Frameworks are share libraries that can be integrated by the developer into the apps and use the functionalities built-in into those libraries. But even the most powerful framework falls short without proper documentation, thus affecting their adoption. The basic purpose of building Frameworks is to help other developers to use the functionalities by integrating the Framework to their app. This requires good documentation that explains each and every steps in the integration process and also about how to make use of the Framework capabilities.

Documentation website is the map that guides developers through using your Framework. So, how do you craft documentation that shines as brightly as your code? Let's delve into the nitty-gritty of crafting top-notch iOS framework documentation website.

Where to Host the Documentation of your iOS Framework

*Choosing the right way to host your documentation is crucial. *

Creating Documentation website from Scratch

Writing documentation from scratch gives you complete control over the structure, design, and features. You can tailor it to fit the specific needs and aesthetics of your iOS framework. But this can be time-consuming, especially for large projects as it requires significant investment in planning, writing, and maintaining content.

Using Documentation Website generators

Website generators like GitPages or Docusaurus are best suited for documentation hosting.

They provide a quick start, allowing you to set up documentation with minimal effort. Availability of templates and pre-built themes helps streamline the process. Website generators enforce consistency in structure and style, making it easier for users to navigate and understand the content. This is particularly useful for maintaining a professional and cohesive look across projects.

When choosing a website generator, it is ideal to choose one that works based on mark-down language. This will help you switch between multiple such tools with ease if needed.

Creating a Readme File/First documentation page

Don't underestimate the power of a well-written First page/Readme file. It's the first impression your framework makes! Keep it updated and consider employing a templating system to streamline maintenance.

  • A concise overview: First page of the documentation website or the Readme file should clearly explain what your framework is. This is important because there will be situations where developers might land on your documentation page first.

  • Prerequisites and dependencies: This section should specify requirements like the minimum supported OS version of the framework or the need to integrate a distribution framework like Cocoapods.

  • Installation instructions: Make it easy for developers to get started. Provide a step-by-step process to help developers kickstart. If you are distributing the framework via cocoapods or any other distribution medium, make sure detailed steps are provided.

  • Basic usage examples: Showcase the core functionalities through code snippets. Code snippets are a must-have for every documentation website. Make sure any API that the developer has to implement when using the framework is explained with code snippets within the documentation website.

Managing documentation of Versions

As your framework evolves, documentation needs to keep pace. Version control systems like Git help you to,

  • Track changes and revert to previous versions if needed.

  • Use the Tag feature in Git to link specific documentation versions to framework releases.

  • Collaborate with fellow developers on documentation updates.

Semantic Versioning

Implement semantic versioning (major.minor.patch) to communicate changes and guide developers through updates. Website generators like GitPages and Docusaurus support versioning out of the box.

Structure for Versioning

A SemVer version number consists of three parts, separated by dots:

  • Major: Indicates significant breaking changes incompatible with previous versions. Increment for major changes in functionality or API.

  • Minor: Introduces new features or enhancements while maintaining backward compatibility. Increment for new features or bug fixes that don't break existing code.

  • Patch: Fixes bugs or makes minor improvements without changing functionality. Increment for bug fixes or performance enhancements.

Guidelines for Versioning

Here are some key guidelines for implementing SemVer:

  • Start with 1.0.0 for your initial release.

  • Only increment the major version number when:

  • You introduce major breaking changes, such as changes that break backward compatibility.

  • You rewrite a significant portion of your codebase.

  • You completely change the functionality of your framework.

  • Increment the minor version number when you:

  • Add new features that don't break existing code.

  • Make significant enhancements to existing functionality.

  • Increment the patch version number when you:

  • Fix bugs in the existing functionality.

  • Make minor improvements to performance or documentation.

  • Always specify a changelog for each release. This will help developers understand what changes were made in each version.

  • Consider using pre-release identifiers like beta or rc before you release a stable version.

  • Follow the SemVer specification strictly to maintain consistency and avoid confusion.

Organizing the Documentation

  • Organize your documentation by features, making it easy for developers to find what they need.

  • Group related functionalities under clear headings. Use internal linking to connect relevant sections.

  • Provide code snippets in abundance.

Organization of different section in Appxiom Documentation

Release Notes

Keep developers informed about changes with detailed release notes. Make sure each release notes include the following,

  • New features and bug fixes: Highlight what's new and improved.

  • API changes: In case of any API changes that the developer needs to update make sure that is mentioned in the release notes.

  • Breaking changes: Clearly explain any potential compatibility issues.

  • Upgrade instructions: Guide developers on transitioning to the new version, if needed.

Deprecating an API

Deprecating an API in an iOS framework is a crucial step when your framework evolves and some functionalities may need retirement. 

Here's a breakdown of the process to ensure a smooth transition for developers,

  • Announce the Deprecation:

Specify the API: Clearly identify the API to be deprecated along with its current version. Provide detailed information about the function, parameters, and return values.

  • Set a Deprecation Timeline: Choose a reasonable timeframe for sunsetting the API. This period allows developers to adjust their code and find alternatives. Consider a minimum of 6 months for major APIs and shorter periods for minor functionalities.

  • Communicate through official channel: Utilize your developer documentation and release notes to make the announcement visible to your user base.

  • Offer Migration Guidance:

Suggest Alternatives: Recommend new or existing APIs that can replace the deprecated functionality. Provide detailed migration guides with code examples and explanations to ease the transition.

  • Versioning Strategies: If relevant, offer compatibility layers or bridge APIs that work with both the old and new versions, helping developers migrate step-by-step.

  • Deprecation Warnings: Implement warnings within your framework code that notify developers when they use the deprecated API. This provides immediate feedback and encourages the switch to newer methods.

Use @available(*, deprecated) in Swift to mark a function as deprecated.

  • Use __deprecated in Objective-c to mark a function as deprecated.

  • Sunset the API:

Remove the Deprecated API: Once the deprecation period ends, remove the deprecated API from your framework codebase. Clearly document this final step in your changelog and release notes.

Remember: Deprecation is a process, not an event. By following these steps, you can minimize disruption for your developers and ensure a smooth evolution of your dynamic framework.

SEO for making your Docs Discoverable

*Discoverable documentation is every developer's dream. *SEO will make the documentation website discoverable and get to the top of search engine results! Here are the basic steps to achieve it,

  • Keyword Research:

Dive into developer minds: Research relevant keywords developers use to find information about your framework or similar technologies. Tools like Google Keyword Planner, Ahrefs, and SEMrush can be your allies.

  • Target long-tail keywords: While "framework" might be competitive, "best practices for XYZ framework API" could be your golden ticket.

  • Focus on intent: Understand the search intent behind keywords. Are developers looking for tutorials, troubleshooting guides, or API references?

  • Content Optimization:

Craft compelling titles and meta descriptions: Optimize titles and meta descriptions for target keywords while remaining informative and engaging.

  • Structure your content wisely: Use clear headings, subheadings, and bullet points for easy navigation and scannability.

  • Internal linking: Link related pages and tutorials within your documentation, creating a strong knowledge network.

  • Technical SEO:

Mobile-friendliness is key: Ensure your website is mobile-responsive to cater to developers on the go.

  • Speed is your friend: Optimize page loading times for a smooth user experience. Tools like Google PageSpeed and PingDom Insights can help identify bottlenecks.

  • HTTPS for trust: Secure your website with HTTPS to build trust and improve search engine ranking. Most browsers warn users if the website is not secure, diminishing the trust.

  • Building Buzz:

Promote your documentation: Share it on social media, relevant forums, and developer communities.

  • Build relationships: Connect with bloggers, influencers, and other developers in your niche. Guest posts and collaborations can amplify your reach.

  • Monitor and analyze: Track your website traffic and search engine rankings. Use tools like Google Search Console and Google Analytics to understand what's working and what needs improvement.

  • Bonus Tips:

Utilize structured data: Implement schema markup to give search engines richer information about your content, potentially leading to richer search results.

  • Localize your documentation: Consider translating your documentation for wider reach if your target audience is global.

  • Embrace video: Videos and code samples can enhance engagement and improve user experience.

Continuous Improvement

Remember, documentation is a living document, not a set-and-forget affair. Gather feedback from users, actively address issues, and keep it updated alongside your framework.

Following these steps, you should be able to craft iOS framework documentation that is helpful for the developers. It's an investment that pays off in developer satisfaction, and the ultimate success of your creation.

About Appxiom Documentation

We used Docusaurus for create oour documentation. It is based on mark-down language which gets built to vanila html files. This helps in deploying the documentation through an webserver. Visit https://docs.appxiom.com to explore our documentation.

PUSH NOTIFICATIONS IN IOS SWIFT APPS WITH FIREBASE CLOUD MESSAGING (FCM)

Published: · Last updated: · 3 min read
Don Peter
Cofounder and CTO, Appxiom

Push notifications play a crucial role in keeping users engaged with your iOS Swift app by delivering timely updates and personalized content. Firebase Cloud Messaging (FCM) is a robust and reliable solution for implementing push notifications in your iOS apps.

In this guide, we'll explore why you should use FCM, how to integrate it into your Swift app, and when it's most beneficial.

Why Firebase Cloud Messaging (FCM) ?

Cross-Platform Compatibility

FCM offers seamless integration across various platforms, including iOS and Android. This ensures a consistent messaging experience for users using different devices.

Reliability and Scalability

Firebase Cloud Messaging is built on Google Cloud Platform, providing a reliable and scalable infrastructure for handling push notifications, regardless of the size of your user base.

Cloud Functions Integration

FCM integrates seamlessly with Firebase Cloud Functions, allowing you to perform serverless operations triggered by push notifications. This enables you to update user data or perform other backend tasks effortlessly.

How to Integrate FCM in Your iOS Swift App

Set Up a Firebase Project

  • Create a new Firebase project on the Firebase Console.

  • Add your iOS app to the project, and download the GoogleService-Info.plist file.

Install the Firebase SDK

Open your Xcode project and install the Firebase SDK using CocoaPods. Add the following to your Podfile:

pod 'Firebase/Core'
pod 'Firebase/Messaging'

Run pod install in the terminal.

Configure Your App Delegate

In your AppDelegate.swift, import Firebase and configure it in the didFinishLaunchingWithOptions method:

import Firebase

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -&gt; Bool {
FirebaseApp.configure()
// Other setup code
return true
}

Register for Remote Notifications

  • Request user permission to receive notifications and register for remote notifications in the didFinishLaunchingWithOptions method:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -&gt; Bool {
// ... (previous setup code)
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
if granted {
DispatchQueue.main.async {
application.registerForRemoteNotifications()
}
}
}
// ...
}

Implement FCM Delegate Methods

Add the following methods to receive FCM tokens and handle incoming messages:

import FirebaseMessaging

extension AppDelegate: MessagingDelegate {
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
print("FCM Token: \(fcmToken)")
}

func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
print("Received data message: \(remoteMessage.appData)")
}
}

Handle FCM Token and Notifications

Retrieve the FCM token and handle notifications:

import FirebaseMessaging

class YourViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

if let token = Messaging.messaging().fcmToken {
print("FCM Token: \(token)")
}
}
}

The FCM token is a unique identifier assigned to a specific instance of an app on a device. FCM tokens are not permanent and can change. For example, if a user reinstalls your app or clears app data, a new FCM token will be generated.

It's essential to handle token refresh in your app and update your server with the new token when it changes. This ensures that your server can continue to send messages to the correct device.

When to Use FCM Push Notifications

Real-Time Updates

Utilize FCM for delivering real-time updates to users, such as new messages, friend requests, or other time-sensitive information.

Personalized Content

Send personalized notifications based on user behavior or preferences to enhance the user experience and encourage engagement.

Re-Engagement Campaigns

Use push notifications to re-engage users who haven't interacted with your app for a while. Deliver relevant content to bring them back.

Implementing FCM push notifications in your iOS Swift app is a powerful way to enhance user engagement and deliver timely information. With its cross-platform compatibility, reliability, and ease of integration, Firebase Cloud Messaging is a top choice for developers seeking an efficient push notification solution.

COMPLYING WITH GDPR IN IOS APPS: A COMPREHENSIVE GUIDE

Published: · Last updated: · 4 min read
Appxiom Team
Mobile App Performance Experts

The General Data Protection Regulation (GDPR) is a European Union regulation that aims to protect the privacy and personal data of individuals. If your iOS app collects, processes, or stores personal data of EU residents, you must ensure that your app complies with GDPR.

In this guide, we will walk you through the steps to comply with GDPR in your iOS app, complete with Swift code samples.

1. Understand GDPR Principles

Before we dive into the technical aspects, it's crucial to understand the key principles of GDPR:

  • Consent: Users must give informed, explicit consent for their data to be collected and processed.

  • Data Minimization: Only collect and process data that is necessary for your app's functionality.

  • Data Portability: Users have the right to access and transfer their data.

  • Data Security: Implement robust security measures to protect user data.

  • Data Deletion: Allow users to delete their data upon request.

2. Inform Users with a Privacy Policy

Start by providing a clear and concise privacy policy within your app. You can display this during the onboarding process or in the app settings. Ensure that users can easily access and understand your privacy policy.

// Load and display the privacy policy HTML content
if let privacyPolicyURL = URL(string: "https://example.com/privacy-policy.html") {
let request = URLRequest(url: privacyPolicyURL)
webView.load(request)
}

To collect and process user data, you must obtain explicit consent. Create a consent dialog that explains why you need their data and how you will use it. Provide options for users to accept or reject data collection.

// Display a consent dialog
let alertController = UIAlertController(
title: "Data Collection Consent",
message: "We need your data to provide personalized recommendations. Do you consent?",
preferredStyle: .alert
)

let consentAction = UIAlertAction(title: "Consent", style: .default) { _ in
// User consented; start data collection
}

let rejectAction = UIAlertAction(title: "Reject", style: .destructive) { _ in
// User rejected data collection; handle accordingly
}

alertController.addAction(consentAction)
alertController.addAction(rejectAction)
present(alertController, animated: true, completion: nil)

4. Implement Data Minimization

Collect only the data necessary for your app's functionality. Avoid unnecessary data collection to minimize the risk of GDPR violations. Remove any unused data promptly.

5. Secure Data Storage

Protect user data by securely storing it. Use Apple's Keychain Services for sensitive data like passwords and tokens:

import Security

// Store a user's access token securely in the keychain
let accessToken = "user_access_token"
let accessTokenData = accessToken.data(using: .utf8)!
let keychainQuery = [
kSecClass as String: kSecClassGenericPassword as String,
kSecAttrAccount as String: "userAccessToken",
kSecValueData as String: accessTokenData
] as CFDictionary
let status = SecItemAdd(keychainQuery, nil)
if status == errSecSuccess {
print("Access token stored securely.")
}

6. Enable Data Portability

Implement a feature that allows users to access and export their data. Provide options to download data in common formats like JSON or CSV.

// Allow users to export their data
func exportUserData() {
// Prepare user data for export
let userData = ["name": "John Doe", "email": "johndoe@example.com"]

// Convert data to JSON
if let jsonData = try? JSONSerialization.data(withJSONObject: userData, options: []) {
// Offer the JSON file for download
let activityViewController = UIActivityViewController(activityItems: [jsonData], applicationActivities: nil)
present(activityViewController, animated: true, completion: nil)
}
}

7. Implement Data Deletion

Users have the right to request the deletion of their data. Create a feature to allow users to delete their accounts and associated data.

// Delete user account and data
func deleteUserAccount() {
// Perform data deletion// ...// Notify the user
let alertController = UIAlertController(
title: "Account Deleted",
message: "Your account and data have been deleted.",
preferredStyle: .alert
)
let okAction = UIAlertAction(title: "OK", style: .default) { _ in
// Handle user acknowledgment
}
alertController.addAction(okAction)
present(alertController, animated: true, completion: nil)
}

8. Handle Data Breaches

In the unfortunate event of a data breach, you must notify both users and authorities as required by GDPR. Implement a mechanism to detect and respond to breaches promptly.

9. Regularly Update and Audit

Stay compliant by regularly updating your app and privacy policy to reflect changes in data handling practices and GDPR regulations. Perform periodic data audits to ensure compliance.

Conclusion

Complying with GDPR in your iOS app is crucial to protect user privacy and avoid legal consequences. By following the principles of consent, data minimization, security, and providing user rights, you can build a GDPR-compliant app. Always stay informed about evolving GDPR regulations and adapt your app accordingly to maintain compliance.

SOLVING FRAME RATE ISSUES AND APP HANGS IN SWIFTUI IOS APPS

Published: · Last updated: · 7 min read
Appxiom Team
Mobile App Performance Experts

Developing a smooth and responsive iOS app is crucial for providing a great user experience. Frame rate issues and app hangs can be frustrating for users and can lead to negative reviews and decreased app usage.

In this blog post, we will explore common causes of frame rate issues and app hangs in SwiftUI iOS apps and provide solutions and code examples to address them.

Understanding Frame Rate Issues

Frame rate issues occur when an app struggles to render frames at the desired rate, usually 60 frames per second (FPS) on most iOS devices. When the frame rate drops, animations become choppy, and the app feels less responsive. There are several common reasons for frame rate issues:

  • Inefficient View Updates: SwiftUI's declarative nature encourages frequent view updates. If not optimized, this can lead to excessive rendering and reduced frame rates.

  • Heavy Computation on the Main Thread: Performing CPU-intensive tasks on the main thread can block the UI, making the app feel unresponsive.

  • Large Images and Assets: Loading or rendering large images or assets can consume significant memory and processing power, leading to frame rate drops.

Solving Frame Rate Issues in SwiftUI

1. Optimize View Updates

You can optimize view updates by:

  • Using the .onAppear and .onDisappear modifiers to load data only when necessary.

  • Implementing the .id modifier to identify views uniquely and avoid unnecessary updates.

  • Reducing the complexity of SwiftUI view hierarchies.

Example:

struct ContentView: View {
var body: some View {
Text("Optimize your views")
.onAppear {
// Load data when the view appears
loadData()
}
}
}

2. Offload Heavy Computation

Move CPU-intensive tasks to background threads using DispatchQueue or Combine. Ensure that UI updates occur on the main thread.

Using DispatchQueue:

DispatchQueue.global().async {
// Perform heavy computation
let result = performHeavyComputation()

DispatchQueue.main.async {
// Update the UI on the main thread
self.resultLabel = result
}
}

Combine is a powerful framework for handling asynchronous and event-driven code in Swift. You can use Combine to perform background operations in SwiftUI seamlessly. In this example, we'll demonstrate how to use Combine to execute a background operation and update the SwiftUI view when the operation completes.

Let's say you want to fetch some data from a network API in the background and update your SwiftUI view when the data is ready. Here's a step-by-step guide:

  1. Import Combine in your SwiftUI view file:
import SwiftUI
import Combine
  1. Define a ViewModel to handle your data and background operations. Create an ObservableObject class that will hold your data and expose a publisher for notifying view updates.
class MyViewModel: ObservableObject {
@Published var data: [YourDataType] = [] // Replace YourDataType with the actual data type you're using
private var cancellables: Set&lt;AnyCancellable&gt; = []

func fetchData() {
// Simulate a background network request
fetchDataFromNetwork()
.receive(on: DispatchQueue.main) // Ensure updates are on the main thread
.sink { completion in
// Handle completion or errors if needed
} receiveValue: { [weak self] newData in
self?.data = newData
// Update the data when received
}
.store(in: &amp;cancellables)
}

private func fetchDataFromNetwork() -&gt; AnyPublisher&lt;[YourDataType], Error&gt; {
// Implement your network request logic here and return a Combine publisher
// For example, you can use URLSession's dataTaskPublisher
let url = URL(string: "https://your-api-url.com/data")!
return URLSession.shared.dataTaskPublisher(for: url)
.map(\.data)
.decode(type: [YourDataType].self, decoder: JSONDecoder())
.eraseToAnyPublisher()
}
}

Replace YourDataType with the actual type of data you're fetching from the network.

  1. Create a SwiftUI view that observes the changes in your ViewModel and triggers the background operation:
struct ContentView: View {
@ObservedObject private var viewModel = MyViewModel()

var body: some View {
VStack {
if viewModel.data.isEmpty {
Text("Loading...")
} else {
List(viewModel.data, id: \.self) { item in
// Display your data here
Text(item.name)
// Replace with your data properties
}
}
}
.onAppear {
viewModel.fetchData()
// Trigger the background operation when the view appears
}
}
}

In this SwiftUI view, the @ObservedObject property wrapper observes changes to the viewModel, and the onAppear modifier triggers the background operation by calling viewModel.fetchData() when the view appears.

Now, your SwiftUI view will fetch data from the network in the background using Combine and update the view when the data is ready, providing a smooth and responsive user experience.

3. Efficiently Manage Images and Assets

Load images lazily and use asset catalogs for managing image resources. Resize images to appropriate dimensions to reduce memory usage.

In SwiftUI, you can load images lazily using the AsyncImage view. AsyncImage allows you to load and display images asynchronously, which is especially useful for large images or images fetched from the network. Here's how you can use AsyncImage to load images lazily in SwiftUI:

import SwiftUI

struct LazyLoadingImageView: View {
let imageURL: URL
var body: some View {
AsyncImage(url: imageURL) { phase in
switch phase {
case .empty:
// Placeholder while loading (optional)
ProgressView()
case .success(let image):
// Successfully loaded image
image
.resizable()
.scaledToFit()
case .failure(_):
// Handle the failure (e.g., show an error message)
Image(systemName: "xmark.octagon")
.resizable()
.scaledToFit()
.foregroundColor(.red)
@unknown default:
// Handle other unknown states
Text("Unknown state")
}
}
}
}

In the code above:

  • AsyncImage is used to load the image asynchronously from the specified URL.

  • The closure inside AsyncImage receives a Phase parameter, which represents the current state of the image loading process.

  • In the .empty phase, you can display a placeholder (e.g., a ProgressView) to indicate that the image is being loaded.

  • In the .success phase, you can display the loaded image, making it resizable and scaling it to fit the available space.

  • In the .failure phase, you can handle the failure by displaying an error image or a message.

  • The @unknown default case is used to handle any unknown states that might be introduced in future SwiftUI versions.

To use the LazyLoadingImageView in your SwiftUI view, simply provide the URL of the image you want to load:

struct ContentView: View {
var body: some View {
LazyLoadingImageView(imageURL: URL(string: "https://example.com/image.jpg")!)
.frame(width: 200, height: 200)
}
}

Make sure to replace "https://example.com/image.jpg" with the actual URL of the image you want to load.

With AsyncImage, you can efficiently load and display images in a lazy manner, ensuring a smooth user experience, especially when dealing with large images or images from remote sources.

Addressing App Hangs

App hangs occur when the app becomes unresponsive for 250 milli seconds or more due to various reasons, such as blocking the main thread or network requests taking too long. Here are some strategies to prevent app hangs:

1. Use Background Threads for Network Requests

Perform network requests on background threads to avoid blocking the main thread. Combine or URLSession can be used for this purpose.

Example:

let cancellable = URLSession.shared.dataTaskPublisher(for: url)
.map(\.data)
.decode(type: MyModel.self, decoder: JSONDecoder())
.receive(on: DispatchQueue.main)
.sink(receiveCompletion: { _ in }) { data in
// Process data and update UI
}

2. Implement Error Handling

Handle errors gracefully, especially in asynchronous operations, to prevent app hangs and crashes.

do {
let result = try performRiskyOperation()
// Handle the result
} catch {
// Handle the error
}

3. Use Xcode Instruments and APM tools

Use Xcode's Instruments to profile your app's performance, identify bottlenecks, and monitor memory usage. Debugging tools like LLDB can help trace and fix specific issues causing frame rate issues and app hangs.

APM tools are a very much helpful in detecting frame rate issues and App Hangs. Appxiom is such an APM tool that helps in detecting these issues and provides all relevant data points to the developer to fix the issue.

Conclusion

Frame rate issues and app hangs can significantly impact the user experience of your SwiftUI iOS app. By optimizing view updates, offloading heavy computation, efficiently managing assets, and addressing app hangs through proper threading and error handling, you can create a smooth and responsive app that users will love.

Remember that performance optimization is an ongoing process. Regularly test your app on different devices and keep an eye on performance metrics to ensure a consistently great user experience.