繁体   English   中英

如何在iPhone中以编程方式设置锁屏,壁纸和铃声?

[英]How to set lock screen , wallpaper and Ringtone programmatically in iPhone?

在iPhone中我们是否可以通过编程方式设置锁屏,壁纸和铃声?

如果 ,那么请告诉我如何设置它们?

这一切都可以轻松完成,但Apple会拒绝。

可以通过改变com.apple.SpringBoard.plist来更改ringtone ,特别是ringtone键。

以下代码可用于读取自定义铃声的实际铃声标题(由iTunes同步)。

NSMutableDictionary *custDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/private/var/mobile/Media/iTunes_Control/iTunes/Ringtones.plist"];
NSMutableDictionary *dictionary = [custDict objectForKey:@"Ringtones"];

NSArray *keys = [dictionary allKeys];
id key = [keys objectAtIndex:indexPath.row];
NSMutableDictionary *customRingtone = [dictionary objectForKey:key];
NSString *name = [customRingtone objectForKey:@"Name"];
cell.textLabel.text = name;

壁纸可以覆盖:

NSString *homePath1 = @"/private/var/mobile/Library/SpringBoard/HomeBackground.jpg";
NSString *homePath2 = @"/private/var/mobile/Library/SpringBoard/HomeBackgroundPortrait.jpg";
NSString *lockPath1 = @"/private/var/mobile/Library/SpringBoard/LockBackground.jpg";
NSString *lockPath2 = @"/private/var/mobile/Library/SpringBoard/LockBackgroundPortrait.jpg";

这些示例用于我的一个Cydia应用程序中。 对他们来说并不是更多,但这些应该让你朝着正确的方向前进。

由于iOS的变化, WrightsCS答案在某些时候停止了工作。 不幸的是,如果您希望使用未记录的功能,则必须使用此功能。

如果您仍然需要这样做,仅适用于非App Store应用程序 ,此代码适用于iOS 9.3。 但它可能会在任何未来的iOS版本中停止工作。 (见下面的评论:不再在iOS 10中工作)

#import "SBSUIWallpaperPreviewViewController.h"
#import <dlfcn.h>

// open the private framework dynamically
void *handle = dlopen("/System/Library/PrivateFrameworks/SpringBoardUIServices.framework/SpringBoardUIServices", RTLD_NOW);

UIImage *wallpaper = [UIImage imageNamed: @"background.jpg"];

Class sbClass = NSClassFromString(@"SBSUIWallpaperPreviewViewController");
// we create a view controller, but don't display it. 
//  just use it to load image and set wallpaper
SBSUIWallpaperPreviewViewController *controller = (SBSUIWallpaperPreviewViewController*)[[sbClass alloc] initWithImage: wallpaper];
[controller setWallpaperForLocations: 3];  // 3 -> set both for lock screen and home screen

dlclose(handle);

您需要将私有API标头添加到项目中。 您通常可以通过一些搜索在线找到这些, 例如,在这里

在上面的例子中, [SBSUIWallpaperPreviewViewController setWallpaperForLocations:]被调用的3参数:3表示图像应同时用于锁定和主画面。 1表示仅锁定屏幕。 2表示仅主屏幕。


有关我动态打开此框架的原因的说明,请参阅此处的相关答案

我没有关于铃声的答案。 这应该是一个单独的问题:完全不同的API在起作用。

如果你可以检查PLStaticWallpaperImageViewController请使用私有api

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM