简体   繁体   English

我可以使用Apple Push Notification Service让我的应用执行某些操作而不通知iOS 7中的用户吗

[英]Can I use Apple Push Notification Service to have my app do something without notifying user in iOS 7

My Algorithm wishes to work this way- 我的算法希望以此方式工作-

If some desired event occurs at my server then I wish to send a small amount of data to every user my app (foreground or background). 如果我的服务器发生了某些所需的事件,那么我希望向我的应用程序(前台或后台)的每个用户发送少量数据。 But, instead of notifying the user I wish my app to do some computation on data and acknowledge server. 但是,我希望我的应用程序不通知用户,而是对数据进行一些计算并确认服务器。 Remember user must not be notified. 请记住,不得通知用户。

您可以在iOS 7上执行此操作。请参阅iOS应用程序编程指南中的 “定期获取少量内容”部分。

You can use the content-available key in the push notification data and application:didReceiveRemoteNotification:fetchCompletionHandler: . 您可以在推送通知数据和application:didReceiveRemoteNotification:fetchCompletionHandler:使用content-availableapplication:didReceiveRemoteNotification:fetchCompletionHandler: . It could be considered a bit of a hack for your use case and if you try to use it too much you will get limited by Apples system. 对于您的用例来说,它可能算是一点技巧,如果您尝试使用过多,将会受到Apples系统的限制。

You can send "empty" push notification (no text, no sound, no icon). 您可以发送“空”推送通知(没有文字,没有声音,没有图标)。 This kind of notifications is allowed and can be used for synchronization with server (to avoid the expensive repetitive polling from the app side). 允许这种通知,并且可以用于与服务器同步(以避免从应用程序侧进行昂贵的重复轮询)。

If your app is not running then such a notification won't show up among springboard notifications. 如果您的应用未运行,则此类通知将不会显示在跳板通知中。

If it is running then it will receive notification - you just have to make sure you don't show the empty ones (if you are also using notifications with actual contents). 如果它正在运行,它将收到通知-您只需要确保不显示空的(如果您还使用具有实际内容的通知)即可。 Your iOS code would look a bit like: 您的iOS代码如下所示:

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
    NSString *message = nil;
    id alert = [userInfo objectForKey:@"aps"];

    if ([alert isKindOfClass:[NSString class]])
    {
        message = alert;
    }
    else if ([alert isKindOfClass:[NSDictionary class]])
    {
        message = [alert objectForKey:@"alert"];
    }

    if (message)
    {
        if (![message isEqualToString:@""])
        {
            UIAlertView *alertView = [[UIAlertView alloc]
                                      initWithTitle: @"notification"
                                      message: message
                                      delegate: nil
                                      cancelButtonTitle:@"OK"
                                      otherButtonTitles:nil];
            [alertView show];
        }
    }
    else
    {
      //this was an empty notification - here you can enqueue
      //your server-synchronization routine - asynchronously if possible
    }
}

If you don't intend to use any "real" notifications you don't even have to bother with decoding the message. 如果您不打算使用任何“真实”通知,您甚至不必费心解码消息。

If you use ApnsPHP your message generation code would look like this: 如果您使用ApnsPHP,您的消息生成代码将如下所示:

$message = new ApnsPHP_Message($device_apns_token);
$message->setText('');
$message->setSound('');
$message->setExpiry(3600);
$push->add($message);   

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尽管我的应用未运行,是否可以使用服务器端事件来通知iOS用户,而无需使用Apple Push Notification Service? - Is it possible to use server-side events to notify an iOS user despite my app not running, without using Apple Push Notification Service? 如何在iOS应用程序上实现Apple推送通知服务? - How can I implement Apple Push Notification Service on iOS Application? 如何在没有 iPhone 的情况下测试 Apple 推送通知服务? - How can I test Apple Push Notification Service without an iPhone? 当用户在iOS中删除我的应用时,我可以做什么? - Can I do something when user deletes my app in iOS? 如果我使用Apple推送通知服务进行即时通讯,苹果会阻止我的帐户? - If I use Apple Push Notification service for instant messaging will apple block my account? 没有 Apple 推送通知服务的推送通知? - Push Notifications without Apple Push Notification Service? 我应该在我的 iOS 推送通知应用程序中使用核心数据吗? - Should I use core data at my iOS Push Notification App? 人们如何使用我自己创建的IOS应用程序? 我的苹果没有付费帐户 - How can people use my own created IOS app? I have no paid account in apple 如果我使用 Firebase 云消息传递,我是否必须更改我的 Apple 推送通知设置? - Do I have to change my Apple Push Notification settings if I'm using Firebase Cloud Messaging? 我是否需要注册Apple开发者计划才能使用推送通知服务 - Do I need to enroll in apple developer program to use push notification service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM