ios - iOS推送通知的位置请求(当应用程序不在后台运行时)
<p><p>当应用程序不在后台运行时,是否可以发送 iOS 推送通知来获取位置?就像查找我的 iPhone 一样..</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p><strong>UIRemoteNotification</strong> 是你的 friend 。</p>
<p>1) 为您的应用注册远程推送通知:</p>
<pre><code>[ registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound];
</code></pre>
<p>2) 在 applicationDidFinishLaunching 上实现逻辑(处理应用关闭时到达的推送通知)</p>
<pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//...
if() {
//if we're here, apps was launched due to Remote Notification
}
//...
}
</code></pre>
<p>3) 在 didReceiveRemoteNotification 上实现登录(处理应用在前台运行时到达的推送通知)</p>
<pre><code>- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
//...
//business logic for GPS Position
//...
}
</code></pre>
<p>在第 2 步和第 3 步中,实现您的业务逻辑以获取实际的 GPS 位置。</p>
<p>有关 Apple 开发人员文档的更多信息:<a href="http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008194-CH1-SW1" rel="noreferrer noopener nofollow">http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008194-CH1-SW1</a> </p></p>
<p style="font-size: 20px;">关于ios - iOS推送通知的位置请求(当应用程序不在后台运行时),我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/8979878/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/8979878/
</a>
</p>
页:
[1]