Monday, September 28, 2026
HomeiOS Developmentswift - Find out how to manually set off iOS wi-fi information...

swift – Find out how to manually set off iOS wi-fi information permission popup in code?

[ad_1]

I’m growing an app utilizing MultipeerConnectivity to switch information in native community.

Though MultipeerConnectivity is a peer-to-peer community, I’m utilizing it like a server-client structure. The server advertises itself and the shoppers browse for close by servers.

The code on server facet appears to be like like

self.localPeerID = [[MCPeerID alloc] initWithDisplayName:[UIDevice currentDevice].title];
self.mcSession = [[MCSession alloc] initWithPeer:self.localPeerID securityIdentity:nil encryptionPreference:MCEncryptionNone];
self.mcSession.delegate = self;

// The server solely advertises itself.
self.advertiser = [[MCNearbyServiceAdvertiser alloc] initWithPeer:self.localPeerID discoveryInfo:nil serviceType:@"multipeer"];
self.advertiser.delegate = self;
[self.advertiser startAdvertisingPeer];

and the code on shopper facet appears to be like like

self.localPeerID = [[MCPeerID alloc] initWithDisplayName:[UIDevice currentDevice].title];
self.mcSession = [[MCSession alloc] initWithPeer:self.localPeerID securityIdentity:nil encryptionPreference:MCEncryptionNone];
self.mcSession.delegate = self;

// A shopper solely browses for advertisers.
self.browser = [[MCNearbyServiceBrowser alloc] initWithPeer:self.localPeerID serviceType:@"multipeer"];
self.browser.delegate = self;
[self.browser startBrowsingForPeers];

When the app begins promoting or looking, iOS will set off NSLocalNetworkUsageDescription when [self.advertiser startAdvertisingPeer] or [self.browser startBrowsingForPeers] is known as.

Every part is sweet till now. Then after I tapped OK for the above popup on each the server system and the shopper system, solely the shopper system popped up the next wi-fi information permission.

Nonetheless, each the server and the shopper require to make use of wi-fi information to determine the connection. So, when the person first opens the app and select to be the server, the connection can’t be established because the wi-fi information permission does not have an opportunity to indicate up. The person wants to decide on to be the shopper for the primary time, set off the wi-fi information permission, permit it, then return to begin a server.

My query is that, is there a strategy to manually set off the iOS wi-fi information permission popup upfront? Ideally, when the person first opens the app, the wi-fi information permission simply pops up (possibly simply entry a web-based URL?) so it will not pop up later when the person is making an attempt to hook up with different gadgets. Solutions in each swift and objective-c are good to me. Thanks so much!

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments